Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q870 How can I pass a querystring parameter from a link to a function on the linked page?

irt.org | Knowledge Base | JavaScript | Link | Q870 [ previous next ]

Q870 How can I pass a querystring parameter from a link to a function on the linked page?

If you actually want to set this value to the value of a JavaScript variable then:

<script language="JavaScript"><!--
var variableName = 'Hello world';
//--></script>

<a href="newpage.html" onClick="this.href='newpage.html?' + variableName">Linked page</a>

To retrieve it in newpage.html:

<script language="JavaScript"><!--
var variableName = null;

if (location.search.length > 0)
    variableName = location.search.substring(1);

function functionName(text) {
    alert(text);
}

functionName(variableName);
//--></script>

Feedback on 'Q870 How can I pass a querystring parameter from a link to a function on the linked page?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.