Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-26-2009, 06:11 PM   PM User | #1
helavissa
New Coder

 
Join Date: May 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
helavissa is an unknown quantity at this point
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
helavissa is offline   Reply With Quote
Old 05-26-2009, 07:11 PM   PM User | #2
Eldarrion
Regular Coder

 
Join Date: Feb 2009
Location: Wheeling, IL
Posts: 358
Thanks: 5
Thanked 62 Times in 60 Posts
Eldarrion is on a distinguished road
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?
Eldarrion is offline   Reply With Quote
Users who have thanked Eldarrion for this post:
helavissa (05-27-2009)
Old 05-27-2009, 02:33 AM   PM User | #3
helavissa
New Coder

 
Join Date: May 2009
Posts: 19
Thanks: 4
Thanked 0 Times in 0 Posts
helavissa is an unknown quantity at this point
Thank you,
well i thought that since there is a variable, it will just change)
i'm new to javascript
helavissa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:08 PM.


Advertisement
Log in to turn off these ads.