help on passing variable to a function?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jun 2007
Posts: 5
Reputation: dolomitedave is an unknown quantity at this point 
Solved Threads: 0
dolomitedave dolomitedave is offline Offline
Newbie Poster

help on passing variable to a function?

 
0
  #1
Jun 3rd, 2007
Hi,
i have a page with pictures on it, when a user clicks on a picture 2 things happen at the same time a new window pops up and a function is called.

the function does a few checks then calls another page when it calls this page i want to use a querystring, but i want to send data from a database.

i understand js is client side so how do i use server data with it?

the only way i could think of doing this was to put the data needed into a variable then use the code below to call the function and pass on the variable

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="http://www.someurl.com" onclick="openwin(testvar)" target="_blank"><img src=<a rel="nofollow" class="t" href="http://www.pic.com/pic.jpg" target="_blank">http://www.pic.com/pic.jpg</a> width="125" height="125" alt="some picture" border="0"/></a>


then once the function has received the variable it can use it to open the page with the querystring

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function openwin(testvar){
  2. if(popUpsBlocked)window.location.replace("sorrypop.asp");
  3. else
  4. window.open("tmp.asp?var="+testvar);}



this doesnt work for me am i doing something wrong or am i way of track if anyone could point me in the right direction would be really helpful
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: help on passing variable to a function?

 
0
  #2
Jun 5th, 2007
Javascript can't see server data. You need PHP or Ajax instead.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 5
Reputation: dolomitedave is an unknown quantity at this point 
Solved Threads: 0
dolomitedave dolomitedave is offline Offline
Newbie Poster

Re: help on passing variable to a function?

 
0
  #3
Jun 7th, 2007
i understand javascript can't see server data which is why i said before that i have put the data into a variable (which to my understanding can then be used client side) this variable can then be used with the function.

have i still got it wrong??
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: help on passing variable to a function?

 
0
  #4
Jun 7th, 2007
the code you have provided wont work unless 'testvar' is some global variable.

if you want to pass the string 'testvar' to the function openwin:
  1. <a href="http://www.someurl.com" onclick="openwin('testvar')" target="_blank"><img src=http://www.pic.com/pic.jpg width="125" height="125" alt="some picture" border="0"/></a>

note the single quotes; double quotes obviously wont work here.

if that's not the problem; perhaps you need to be more specific about exactly what you're trying to do..
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 5
Reputation: dolomitedave is an unknown quantity at this point 
Solved Threads: 0
dolomitedave dolomitedave is offline Offline
Newbie Poster

Re: help on passing variable to a function?

 
0
  #5
Jun 8th, 2007
thanks for the replies,

ok, yes i want to use the variable with this function so this is how i have declared the variable, i am using ASP as for the server side

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <%
  2. var testvar = (Recordset1.Fields.Item("testvar").Value);
  3. %>

while writing this i have just realised i cant use this variable as it is server side, is there a way i can use this or am i best posting this on ASP forum.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: help on passing variable to a function?

 
0
  #6
Jun 8th, 2007
If i remember my ASP correctly, then this kind of thing should work; although it's somewhat ugly looking...

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <a href="<a rel="nofollow" class="t" href="http://www.someurl.com" target="_blank">http://www.someurl.com</a>" onclick="openwin('<% Response.write(testvar);%>');" target="_blank"><img src=http://www.pic.com/pic.jpg width="125" height="125" alt="some picture" border="0"/></a>

If you're still having problems, the ASP forum might be the better place to ask.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 5
Reputation: dolomitedave is an unknown quantity at this point 
Solved Threads: 0
dolomitedave dolomitedave is offline Offline
Newbie Poster

Re: help on passing variable to a function?

 
0
  #7
Jun 8th, 2007
thanks so much

that work straight away,i thought i had already tried it but obvoiusly not
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC