Link to home
Start Free TrialLog in
Avatar of ksbunger1
ksbunger1Flag for United States of America

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")&">"&objRS2("Title")
      objRS2.MoveNext
      Loop
      Response.Write "</select>"
      Response.Write "</td></tr>"

objRS2.Close
Set objRS2 = Nothing
%>
Avatar of raj3060
raj3060
Flag of United States of America image

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.getElementById('hidden_Field').value
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.asp?val=" + str,'', 'toolbar=0,scrollbars=yes,location=0,statusbar=yes,menubar=0,resizable=yes,width=850,height=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")&">"&objRS2("Title")
      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.asp?val=" + str,'', 'toolbar=0,scrollbars=yes,location=0,statusbar=yes,menubar=0,resizable=yes,width=850,height=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>"
%>

Avatar of ksbunger1

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.getElementById('hidden_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?
Before you open the popUp:

document.getElementById('HiddenField').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.getElementById('HiddenField').value
Ok, my value is ASP code. so would it look something like this?


 -Parent page-
document.getElementById('HiddenField').value = <%=UserID%>
<input type='hidden' id='HiddenField' name = 'HiddenField'/><a href=""emailPopup.asp"" onclick=""NewWindow(this.href,'name','450','100','no');return 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.getElementById('HiddenField').value
</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
You use HiddenField
ASKER CERTIFIED SOLUTION
Avatar of raj3060
raj3060
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
should be:

href="emailPopup.asp"

for some reason you had double double quotes.
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.getElementById('HiddenField').value

document.getElementById('HiddenField1').value = userId // this should be a hidden field in your child page
</script>