Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

window.navigate func 1

Status
Not open for further replies.

thompom

Technical User
Dec 4, 2006
395
GB
i am trying to pass variables to a function but cant get the variables into the function -

function
Code:
<script>
function fullwin(x_vehicleid, x_make, x_model, x_registration) {
window.navigate("3coltemp.asp?pagesetupid=35&x_make="+x_make+"&x_model="+x_model+"&vehicleid="+x_vehicleid+"&registration="+x_regsitration);
}
</script>

onclick tr event
Code:
<tr class="ewTableRow" style='cursor:pointer;cursor:hand;' onClick="fullwin(AETV82397118,VAUXHALL,AGILA,HG07EYK);">

thanks
 
That's because you're trying to pass strings to the function w/o encapsulating them in quotes. So, that makes your function believe they are variable names (consequently, of variables that likely do not exist). Make the following change:
(on a side note, you can get rid of the cursor:hand style decoration - it's IE only, and IE understands cursor:pointer, so there's no need to ever use hand)
Code:
<tr class="ewTableRow" style='cursor:pointer;[s]cursor:hand;[/s]' onClick="fullwin([!]'[/!]AETV82397118[!]'[/!],[!]'[/!]VAUXHALL[!]'[/!],[!]'[/!]AGILA[!]'[/!],[!]'[/!]HG07EYK[!]'[/!]);">

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
thanks for your idea - put the vars in quotes but still not right

source
Code:
<script>
function fullwin(x_vehicleid, x_make, x_model, x_registration) {
window.navigate("3coltemp.asp?pagesetupid=35&x_make="+x_make+"&x_model="+x_model+"&vehicleid="+x_vehicleid+"&registration="+x_registration);
}

<tr class="ewTableRow" style='cursor:pointer;' onClick="fullwin('AETV82397118','VAUXHALL','AGILA','HG07EYK');">
...
</tr>
</script>
 
I'm sorry, but posting your code with the changes I've already suggested and then not giving me any new detail of what type of error you're receiving doesn't give me much to go on....

I will throw out a few general suggestions that may or may not have to do with your problem.

1) When changing the url of a page with javascript I always use [tt]document.location = "[/tt] instead of the window.navigate method. Maybe try that to see if it helps.

2) If you're unsure if the variables being passed to the function are incorrect, try alerting the values once you get to the function. This is one of the first things you should always do when trying to debug a problem so that you can fully understand what's going on, and take a top-down approach at solving the problem

Code:
function fullwin(x_vehicleid, x_make, x_model, x_registration) {
   [!]alert(x_vehicleid);[/!]
   [!]alert(x_make);[/!]
   [!]alert(x_model);[/!]
   [!]alert(x_registration);[/!]
   var newUrl = "3coltemp.asp?pagesetupid=35&x_make=" + x_make + "&x_model=" + x_model + "&vehicleid=" + x_vehicleid + "&registration=" + x_registration;
   [!]alert(newUrl);[/!]
   document.location = newURL;
}


-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
apologees kaht - im getting a 'newURL is undefined' error
in this line i think
document.location = newURL;
but the vars are now being shown fine in the alert boxes


 
wow, I can't believe I made that mistake, shame on me....

Javascript is case sensitive:
Code:
document.location = newU[!]rl[/!];

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
thanks alot kaht - i really apreciate it, heres a *
[will look out for case in future]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top