/    Sign up×
Community /Pin to ProfileBookmark

Passing Variable to a pop-up using onclick

Question…..

Using the following line of code is it possible to pass a value from a text box to the popup window?

[code=html]<input type=”text” name=”vessNam”>
<script language=”javascript”>
var lookup = booking.vessNam.value
</script>
<a onclick=”window.open(‘popup-picker-demo.html?ID=lookup’,’popuppage’,’width=700,height=200,top=100,left=100′);”>open</a>[/code]

I have a huge db that i am trying to search but it is killing my main page so my idea was to use a like search in asp on a popup page using the text entered into a text box on the main page. I then use js to send that value back to main page.

any help appreciated.

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 09.2007 — Reference the value from the child window:opener.document.lookup
Copy linkTweet thisAlerts:
@orionbrock32authorJan 09.2007 — Maybe I should have mentioned how completely inept I am at js.

That being said I think I could use this variable on the child window and place it in a hidden box then pull that value into an asp variable to be used in my query.

Now my next question would be how do I place

opener.document.lookup

in the value of a text or hidden box?
Copy linkTweet thisAlerts:
@FangJan 09.2007 — document.forms[0].hiddenBox.value=opener.document.lookup
Copy linkTweet thisAlerts:
@orionbrock32authorJan 10.2007 — Okay this is what I have on the parent

[code=html]
<input type="text" name="vessNam">
<script language="javascript">
var lookup = booking.vessNam.value
</script>
<a onclick="window.open('popup-picker-demo.html?ID=booking.vessNam.value','popuppage','width=700,height=200,top=100,left=100');">open</a>
[/code]


and what the child looks like

[code=html]

<SCRIPT LANGUAGE="JavaScript">

document.selectform.hiddenBox.value=opener.document.lookup

</SCRIPT>

</HEAD>

<BODY>

<center>
<form name=selectform>

<input type="text" name="hiddenbox">

[/code]


But I'm still not getting anything. I am sure it has to do with the fact that I am not using the js correctly on the child.

Thanks
Copy linkTweet thisAlerts:
@FangJan 11.2007 — The lookup variable is not updated nor called correctly &lt;script type="text/javascript"&gt;
window.onload=function() {
document.selectform.hiddenBox.value=opener.document.booking.vessNam.value;
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@orionbrock32authorJan 11.2007 — Ok I am still getting nothing, do I need to have some special js on the parent

[code=html]
<input type="text" name="vessNam">
<script language="javascript">
var lookup = booking.vessNam.value
</script>
<a onclick="window.open('popup_test.asp','popuppage','width=700,height=200,top=100,left=100');">open</a>

[/code]



[code=html]
<html>

<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Shawn A. Mann ([email protected]) -->
<!-- Web Site: http://www.laughingshaman.com -->
<!-- Modified By: Ronnie T. Moore, Editor -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function sendValue(s){
var selvalue = s.options[s.selectedIndex].value;
window.opener.document.booking.vessNam.value = selvalue;
window.close();
}
// End -->
</script>

<script LANGUAGE="JavaScript">
window.onload=function() {
document.selectform.hiddenBox.value=opener.document.booking.vessNam.value;
}
</script>
</HEAD>

<BODY>

<center>
<form name=selectform>

<input type="text" name="hiddenbox">

<p>
<input type=button value="Item Select Item" onClick="sendValue(this.form.hiddenbox);">
</form>
</center>

</body>

</html>

[/code]


Probably something simple but any help would be appreciated.

I am getting nothing in the box requested.
Copy linkTweet thisAlerts:
@FangJan 11.2007 — Wrong camel-case in [I]hiddenbox[/I]
Copy linkTweet thisAlerts:
@orionbrock32authorJan 11.2007 — I am an indiot, thanks for the help.
Copy linkTweet thisAlerts:
@orionbrock32authorJan 11.2007 — ok so that works like it is supposed however there is an error in my logic, so now i pose a new question .....

when calling the popup is it possible to include the textbox value in the link

[code=html]
<a onclick="window.open('popup_test.asp','popuppage','width=700,height=200,top=100,left=100');">
[/code]


instead of popup_test.asp how would you make it popup_test.asp?name=textbox.value?
Copy linkTweet thisAlerts:
@FangJan 12.2007 — Parent:&lt;a onclick="window.open('popup_test.htm?id='+booking.vessNam.value,'popuppage','width=700,height=200,top=100,left=100');"&gt;open&lt;/a&gt;

Child:&lt;script type="text/javascript"&gt;
window.onload=function() {
var str=location.search.split('=');
document.selectform.hiddenBox.value=str[1];
}
&lt;/script&gt;
Copy linkTweet thisAlerts:
@orionbrock32authorJan 12.2007 — Sweet sassy molassy, works like a charm.

thanks Fang i appreciate all the help!
×

Success!

Help @orionbrock32 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...