...

View Full Version : passing variables through query string



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

Eldarrion
05-26-2009, 07: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() {
window.location="displayVar.php?sq1="+sq1;
}


See how that goes for you.

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum