ksbunger1
asked on
Javascript help, to pass info to an ASP popup.
I'm needing a way to pass a "UserID" to an ASP classic popup that will then place it in the proper location of the query string. The UserID variable is already available to me on the parent page. I just need to send it to the "child" pop up page. Here is what my popup currently looks like. Maybe some JavaScript will be the easiest way?
<%
Dim objRS2
set objRS2 = Server.CreateObject("ADODB .Recordset ")
'------Get the article list-------
Dim Arts
objRS2.Open "SELECT * from Users where ID=USERID NEEDS TO GO HERE", connection, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Arts = objRS2("ArticlesArray")
objRS2.Close
objRS2.Open "SELECT A.ID,A.Title FROM Articles A WHERE A.ID IN ("& Arts &") ORDER BY A.Title", cn, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Response.Write "<tr><td>"
Response.Write "<select name=""articleID"">"
do While not objRS2.EOF
Response.Write "<OPTION VALUE="&objRS2("ID")&">"&o bjRS2("Tit le")
objRS2.MoveNext
Loop
Response.Write "</select>"
Response.Write "</td></tr>"
objRS2.Close
Set objRS2 = Nothing
%>
<%
Dim objRS2
set objRS2 = Server.CreateObject("ADODB
'------Get the article list-------
Dim Arts
objRS2.Open "SELECT * from Users where ID=USERID NEEDS TO GO HERE", connection, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Arts = objRS2("ArticlesArray")
objRS2.Close
objRS2.Open "SELECT A.ID,A.Title FROM Articles A WHERE A.ID IN ("& Arts &") ORDER BY A.Title", cn, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Response.Write "<tr><td>"
Response.Write "<select name=""articleID"">"
do While not objRS2.EOF
Response.Write "<OPTION VALUE="&objRS2("ID")&">"&o
objRS2.MoveNext
Loop
Response.Write "</select>"
Response.Write "</td></tr>"
objRS2.Close
Set objRS2 = Nothing
%>
I am not too sure as to where you need the popup but from the code i would assume it onChange Event of the SELECT(dropdown...)
I think u should use, i haven't tested it though so if you could do that
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showPopUp(str) {
window.open("yourASPPage.a sp?val=" + str,'', 'toolbar=0,scrollbars=yes, location=0 ,statusbar =yes,menub ar=0,resiz able=yes,w idth=850,h eight=600, left = 50,top = 100');
}
// End -->
</script>
<%
Dim objRS2
set objRS2 = Server.CreateObject("ADODB .Recordset ")
'------Get the article list-------
Dim Arts
objRS2.Open "SELECT * from Users where ID=USERID NEEDS TO GO HERE", connection, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Arts = objRS2("ArticlesArray")
objRS2.Close
objRS2.Open "SELECT A.ID,A.Title FROM Articles A WHERE A.ID IN ("& Arts &") ORDER BY A.Title", cn, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Response.Write "<tr><td>"
Response.Write "<select name=""articleID"" onchange=""showPopUp(this. value)"">"
do While not objRS2.EOF
Response.Write "<OPTION VALUE="&objRS2("ID")&">"&o bjRS2("Tit le")
objRS2.MoveNext
Loop
Response.Write "</select>"
Response.Write "</td></tr>"
objRS2.Close
Set objRS2 = Nothing
%>
I think u should use, i haven't tested it though so if you could do that
Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showPopUp(str) {
window.open("yourASPPage.a
}
// End -->
</script>
<%
Dim objRS2
set objRS2 = Server.CreateObject("ADODB
'------Get the article list-------
Dim Arts
objRS2.Open "SELECT * from Users where ID=USERID NEEDS TO GO HERE", connection, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Arts = objRS2("ArticlesArray")
objRS2.Close
objRS2.Open "SELECT A.ID,A.Title FROM Articles A WHERE A.ID IN ("& Arts &") ORDER BY A.Title", cn, adOpenForwardOnly, adLockReadOnly
objRS2.MoveFirst
Response.Write "<tr><td>"
Response.Write "<select name=""articleID"" onchange=""showPopUp(this.
do While not objRS2.EOF
Response.Write "<OPTION VALUE="&objRS2("ID")&">"&o
objRS2.MoveNext
Loop
Response.Write "</select>"
Response.Write "</td></tr>"
objRS2.Close
Set objRS2 = Nothing
%>
I have tested it statically and it works perfectly fine......Check this out...
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showPopUp(str) {
window.open("yourASPPage.a sp?val=" + str,'', 'toolbar=0,scrollbars=yes, location=0 ,statusbar =yes,menub ar=0,resiz able=yes,w idth=850,h eight=600, left = 50,top = 100');
}
// End -->
</script>
<%
Response.Write "<select name=""articleID"" onchange=""showPopUp(this. value)"">"
Response.Write "<OPTION VALUE=""1"">BUGS</option>"
Response.Write "<OPTION VALUE=""2"">BUGS 2</option>"
Response.Write "<OPTION VALUE=""3"">BUGS 3</option>"
Response.Write "<OPTION VALUE=""4"">BUGS 4</option>"
Response.Write "</select>"
%>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function showPopUp(str) {
window.open("yourASPPage.a
}
// End -->
</script>
<%
Response.Write "<select name=""articleID"" onchange=""showPopUp(this.
Response.Write "<OPTION VALUE=""1"">BUGS</option>"
Response.Write "<OPTION VALUE=""2"">BUGS 2</option>"
Response.Write "<OPTION VALUE=""3"">BUGS 3</option>"
Response.Write "<OPTION VALUE=""4"">BUGS 4</option>"
Response.Write "</select>"
%>
ASKER
raj3060,
"you can create a hidden field and before you go to popup save the value to hidden field and then inside your PopUp use:
document.opener.getElement ById('hidd en_Field') .value"
I think this is exactly what I need but I am still having trouble. how do I save the value to a hidden field? Does this have to be in a form? because right now I just have a link opening the popup box. Once the popup box is open I just need the variable to be hidden so that I may call it. What should the code look like on the parent page?
Bugs,
Thank you for your post, but all I'm needing is the javascript to pass the variable to my popup, no need to display it in the drop down. Am I reading your code wrong?
"you can create a hidden field and before you go to popup save the value to hidden field and then inside your PopUp use:
document.opener.getElement
I think this is exactly what I need but I am still having trouble. how do I save the value to a hidden field? Does this have to be in a form? because right now I just have a link opening the popup box. Once the popup box is open I just need the variable to be hidden so that I may call it. What should the code look like on the parent page?
Bugs,
Thank you for your post, but all I'm needing is the javascript to pass the variable to my popup, no need to display it in the drop down. Am I reading your code wrong?
Before you open the popUp:
document.getElementById('H iddenField ').value = 'Your Value'
Keep your hidden field inside your body tag:
<input type='hidden' id='HiddenField' name = 'HiddenField'/>
now Call PopUp.
Then in PoPup when you load the page:
document.opener.getElement ById('Hidd enField'). value
document.getElementById('H
Keep your hidden field inside your body tag:
<input type='hidden' id='HiddenField' name = 'HiddenField'/>
now Call PopUp.
Then in PoPup when you load the page:
document.opener.getElement
ASKER
Ok, my value is ASP code. so would it look something like this?
-Parent page-
document.getElementById('H iddenField ').value = <%=UserID%>
<input type='hidden' id='HiddenField' name = 'HiddenField'/><a href=""emailPopup.asp"" onclick=""NewWindow(this.h ref,'name' ,'450','10 0','no');r eturn false"">add link </a>
Does this have to be in a form? Can I use a link instead?
-Child page (Popup)-
<script langauge="javascript">
document.opener.getElement ById('Hidd enField'). value
</script>
and when I call the variable in the child page would I use HiddenField or UserID?
Thanks
-Parent page-
document.getElementById('H
<input type='hidden' id='HiddenField' name = 'HiddenField'/><a href=""emailPopup.asp"" onclick=""NewWindow(this.h
Does this have to be in a form? Can I use a link instead?
-Child page (Popup)-
<script langauge="javascript">
document.opener.getElement
</script>
and when I call the variable in the child page would I use HiddenField or UserID?
Thanks
@ksbunger1
Yes you are reading my code wrong. I am passing the dropdown value to the popup and not vice verca.
Cheers
Yes you are reading my code wrong. I am passing the dropdown value to the popup and not vice verca.
Cheers
You use HiddenField
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
should be:
href="emailPopup.asp"
for some reason you had double double quotes.
href="emailPopup.asp"
for some reason you had double double quotes.
ASKER
Haha, yeah, cause I pasted from my ASP code which is in a response.Write... So it has to have those ;) thanks again for your help. Works great! Now if I can just figure out how to convert a javascript variable to a ASP variable I will be good to go.
Reverse the process.
Save JS value to Hidden field and then assign it to ASP.
-Child page (Popup)-
<script langauge="javascript">
var userId = document.opener.getElement ById('Hidd enField'). value
document.getElementById('H iddenField 1').value = userId // this should be a hidden field in your child page
</script>
Save JS value to Hidden field and then assign it to ASP.
-Child page (Popup)-
<script langauge="javascript">
var userId = document.opener.getElement
document.getElementById('H
</script>
document.opener.getElement