2

I have two html pages example1.html and example2.html ,how can i pass a javascript variable username from example1.html to example2.html in querystring.

<script type="text/javascript" >
    $(document).ready(function() {
        $('#SubmitForm').submit(function() {
            var username = ($("#username").val());
               ...........
                ..........
              ..............
               .........

</script>
<body>
<div id="example2"><a href="http://localhost:1894/blockseek8-9-2010/example2.html?Var1=username" class="MainNav"></a></div>
</body>

3 Answers 3

2

You can modify the href attribute of your link:

$("#example2 a").attr("href", url + "?var1=" + username);

If username uses special characters you will need to url encode it.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the reply, how do i retreive the username on example2.html page?
You are welcome. See netlobo.com/url_query_string_javascript.html for your question.
1

You could either use PHP, or set location.search.

1 Comment

I dont want to use serverside script ,just i want to retrieve those values in example2.html
1

What about using cookies? http://plugins.jquery.com/project/Cookie - no need to modify query string :)

1 Comment

Cookies are persistent and get sent with every request to the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.