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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing and receiving variables 1

Status
Not open for further replies.

ca8msm

Programmer
May 9, 2002
11,327
GB
I have a page where users submit data. On the page the user has to enter an ID of a book. If they do not know the ID, I want them to be able to click find and a new pop up window appears with search facilities. I then need to pass the book id back to the original page.

I know that it can be done easily (i.e. by form or querystring) but im not sure on the best process. What I want to happen is that when the user finds and selects the correct book (in the pop up window), the ID is inserted into the original textbox (on the main input page) without re-submitting the page and therefore having to refresh it (I hope that made sense). Is this possible?
 


popwindow.asp
<%
set cn=server.createobject(&quot;adodb.connection&quot;)
cn.open(yourConnectionString)

set rs = cn.execute(&quot;select ID, title FROM bookTable&quot;)

optionStr = &quot;<option value=''>&quot;
do while not rs.eof
optionStr = optionStr & &quot;<option value='&quot; & rs(0) & &quot;'>&quot; & rs(1)
rs.movenext
loop
%>

<script>
function selectionMade(){
selectedValue = document.myForm.mySelect.options[document.myForm.mySelect.selectedIndex].value
window.opener.formName.fieldName.value = selectedValue
self.close()
}
</script>

<form name=&quot;myForm&quot;>
<select name=&quot;mySelect&quot; onChange=&quot;selectionMade()&quot;>
<%=optionStr%>
</select>
</form>



Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
To quick for me, you don't sleep do you mwolf? :)

01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101
29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
You'll never hear a response from me after 4PM EDT.... ;)

I get up early...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Sorry I don't quite understand. Doesn't this just populate the current page with some values from the database. It doesnt actually send the information from the pop-up window back to the main form does it?
 
Yes, the javascript that executes onSelect will populate the main page input box using this line of code...

window.opener.formName.fieldName.value = selectedValue

you need to replace &quot;formName&quot; with the name of your form and &quot;fieldName&quot; with the name of the input box....

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
I just realised that! Sorry about that - it has done exactly what I wanted.

Thank you.
 
That was neat! What if you wanted that popup to have an &quot;Add book&quot; function instead, and then add that book into a <OPTION VALUE='BOOKNAME'> in an existing <SELECT> on the parent page. Is that also possible without reloading the parent page?

Palooka
 
Palooka - If you add a book, you will need to generate a new ID. You could do this all on the pop window (but it does require another server call) and then when the new ID is returned, populate the parent with the info...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top