Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 632
  • Last Modified:

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
%>
0
ksbunger1
Asked:
ksbunger1
  • 7
  • 3
  • 3
1 Solution
 
raj3060Commented:
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
0
 
bugs021997Commented:
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
%>

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
bugs021997Commented:
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>"
%>

0
 
ksbunger1Author Commented:
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?
0
 
raj3060Commented:
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
0
 
ksbunger1Author Commented:
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
0
 
bugs021997Commented:
@ksbunger1

Yes you are reading my code wrong. I am passing the dropdown value to the popup and not vice verca.


Cheers
0
 
raj3060Commented:
You use HiddenField
0
 
raj3060Commented:
-Parent page-

<input type='hidden' id='HiddenField' name = 'HiddenField' />
<a href=""emailPopup.asp"" onclick="document.getElementById('HiddenField').value = <%=UserID%>;NewWindow(this.href,'name','450','100','no');return false">add link </a>


-Child page (Popup)-
<script langauge="javascript">
var userId = document.opener.getElementById('HiddenField').value
</script>
0
 
raj3060Commented:
should be:

href="emailPopup.asp"

for some reason you had double double quotes.
0
 
ksbunger1Author Commented:
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.
0
 
raj3060Commented:
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>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now