View Full Version : passing parameters using java script
terrytao
11-21-2002, 07:41 PM
Hi,
I can pass parameters from one page to another by doing this:
<a href="videoList.asp?Category=<%=(rsCategory.Fields.Item("Category").Value)%>"></a>
But I have trouble to do that using javascript:
<a href="javascript:window.open('videoList.asp'?+.....
I was trying to open up a pop up window by clicking a text link and pass that text value to the pop up window.
Can anybody help? thanks very much!
Terry
A1ien51
11-21-2002, 08:13 PM
You can do it this way
<a href="videoList.asp?Category=<%=(rsCategory.Fields.Item("Category").Value)%>" target="_blank"></a>
or this way (i believe)
<a href="javascript:window.open('videoList.asp?Category=<%=(rsCategory.Fields.Item("Category").Value)%>'"></a>
terrytao
11-21-2002, 10:04 PM
Thanks Alien51 for your help. The code works great!--the parameter has been passed successfully.
<A HREF="javascript:window.open('ageVerification.asp?Category=<%=(category2.Fields.Item("Category").Value)%>')"><%=(category2.Fields.Item("category").Value)%></A>
The reason I'm using javascript to open a pop up window is because I want it to be a certain size, e.g., 200X300. But when I put size parameters in the code, as shown below, an error message says "Invalid Argument" , any ideas?
<A HREF="javascript:window.open('ageVerification.asp?Category=<%=(category2.Fields.Item("Category").Value)%>', 'width=200, height=300')"><%=(category2.Fields.Item("category").Value)%></A>
thanks again,
glenngv
11-22-2002, 01:45 AM
the 2nd parameter of window.open is the target where you want the new window to be opened.
use void to before the window.open method so that it will not return the window object.
use server.urlencode if category can contains special characters like spaces, ampersands, and the like
<A HREF="javascript:void window.open('ageVerification.asp?Category=<%=server.urlencode(category2.Fields.Item("Category").Value)%>','_blank','width=200, height=300')"><%=(category2.Fields.Item("category").Value)%></A>
or better you can put it in a function if you call it on several links
function openWin(url,target,w,h){
window.open(url,target,"width="+w+",height="+h);
return;
}
call it like this:
<A HREF="javascript:doOpen('ageVerification.asp?Category=<%=server.urlencode(category2.Fields.Item("Category").Value)%>','_blank',200,300)"><%=(category2.Fields.Item("category").Value)%></A>
or to be safe in case javascript is disabled:
<A href="ageVerification.asp?Category=<%=server.urlencode(category2.Fields.Item("Category").Value)%>" target="_blank" onclick="doOpen('ageVerification.asp?Category=<%=server.urlencode(category2.Fields.Item("Category").Value)%>','_blank',200,300);return false;"><%=(category2.Fields.Item("category").Value)%></A>
terrytao
11-22-2002, 04:32 PM
Thank you very much, Glenn. --Terry
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.