Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2009
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts

    passing variables through query string

    Hi,

    I want to pass some variables from one page to the other. Question is, why the following won't work?


    <script>
    var sq1;

    function assignVar(value){
    sq1 = value;
    }
    </script>



    <img src="http://www.teconic.com/graphics/blue_ball.jpg" alt="blue" onmouseDown= " assignVar('1'); " />

    <SCRIPT LANGUAGE="JavaScript" type="text/javascript">

    document.write('<a href="displayVar.php?sq1='+sq1+'">another page</a>');

    </SCRIPT>

    The value of sq1 will remain undefined.
    It is updating actually, but why it stays the same in query string?

    Thank you for reading

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    You're calling the document.write before you have a value for sq1. How exactly do you expect it to work in that case? Though essentially, I see no point in the whole thing either, but eh... I guess you have your reasons.

    Try the following function, called onclick on a button or whatever:

    Code:
    function checkVar() {
    	window.location="displayVar.php?sq1="+sq1;
    }
    See how that goes for you.

    Additionally SCRIPT LANGUAGE="JavaScript" is deprecated and obsolete, avoid using it.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • Users who have thanked Eldarrion for this post:

    helavissa (05-27-2009)

  • #3
    New Coder
    Join Date
    May 2009
    Posts
    19
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you,
    well i thought that since there is a variable, it will just change)
    i'm new to javascript


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •