View Full Version : passing variables through query string

05-26-2009, 07:11 PM

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

var sq1;

function assignVar(value){
sq1 = value;

<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>');


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

Thank you for reading

05-26-2009, 08:11 PM
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:

function checkVar() {

See how that goes for you.

Additionally SCRIPT LANGUAGE="JavaScript" is deprecated and obsolete, avoid using it.

05-27-2009, 03:33 AM
Thank you,
well i thought that since there is a variable, it will just change)
i'm new to javascript