Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How to make the same pop up pass the value to several input, without having to write different pop up, for different input. Its a bit too advance for me to sort it out.
For example:
Index.html;
<input type=text name=input1 /> [a]Popup[/a]
<input type=text name=input2 /> [a]Popup[/a]Popup.html;
<select>
<option>
</select>

Using your previous example:
function font() {
document.formname.font_type.value = "Arial";
document.formname.field2.value = "Arial";
document.formname.field3.value = "Arial";}
Michael J

I am still try to work it out. I'm sure that i need to put 'id' or 'name' for the link that call the pop up. But how do i tell the pop up that it was click from that id, so it only pass the value to that id.

OK, I think I understand. If this is not what you want I think you need to restate your problem giving very specific examples.
On the popup page, instead of putting the javascript into the link itself, have the link call a function to do all the work. Here's an example
[script]
function popParent(switchVal) {oForm = opener.document.formname;
switch(switchVal)
case"option1":
oForm.font_type.value='Arial';
oForm.font_size.value='8';
oForm.font_color.value='red';
self.close();case"option3":
oForm.font_type.value='Courier';
oForm.font_size.value='10';
oForm.font_color.value='green';
self.close();case"option3":
oForm.font_type.value='Times';
oForm.font_size.value='12';
oForm.font_color.value='blue';
self.close();
}}
[/script]
[a href="#" onclick="popParent("option1")">Link1[/a]
[a href="#" onclick="popParent("option2")">Link1[/a]
[a href="#" onclick="popParent("option3")">Link1[/a]Michael J

That is a great example to pass several value at one click. But its not what I want. I try to restate with specific example below;
1) Index.html
Font1: [input type="text] [a onclick="PopUP('Pop.html')]Link1[/a]
Font2: [input type="text] [a onclick="PopUP('Pop.html')]Link2[/a]
Font3: [input type="text] [a onclick="PopUP('Pop.html')]Link3[/a]
2) Pop.html[a]Arial[/a]
[a]Courier[/a]
[a]Times[/a]
[a]Tahoma[/a]- From 'Index.html', if I click 'Link 1', it will trigger 'Pop.html'. From 'Pop.html', if I click 'Arial', it will pass 'Arial' to 'Font1' text input.
- if I click 'Link 2', it will trigger "the same" 'Pop.html'. From 'Pop.html', if I click 'Times', it will pass 'Times' to 'Font2' text input.The reason I need to do this is to avoid having to write '40' pop-up if I have '40' font input. Therefore, all the link will trigger "the same" pop-up.

Easy enough. In your index.html change your PopUp function and links as follows
function popUp(URL,field) {
inputField = field;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400px,height=500px,left = 312,top = -16');");
}Font1: [input type="text] [a onclick="PopUP('Pop.html',this)]Link1[/a]
Font2: [input type="text] [a onclick="PopUP('Pop.html',this)]Link2[/a]
Font3: [input type="text] [a onclick="PopUP('Pop.html',this)]Link3[/a]
Then on your popup page change the function to set the value like this:function popParent(value) {
opener.inputField.value = value;
}Michael J

It didn't pass the value to input field. Here's what i did;
1) Index.html;
[html]
[head]
[title][/title]
[script type="text/javascript"]
function popUp(URL,field) {
inputField = field;
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=100,height=100,left = 462,top = 334');");
}
[/script][/head]
[body]
[form name="formname"]
[input type="text" name="font1"] [a href="javascript:void()" onclick="popUp('popme.html',this)"]Link1[/a]
[input type="text" name="font2"] [a href="javascript:void()" onclick="popUp('popme.html',this)"]Link2[/a]
[/form]
[/body]
[/html]2) popme.html;
[html]
[head]
[script type="text/javascript"]
function popParent(value) {
opener.inputField.value = value;
}
[/script]
[/head]
[body]
[a href="javascript:void()" onclick="popParent('Arial')"]Arial[/a]
[a href="javascript:void()" onclick="popParent('Verdana')"]Verdana[/a]
[/body]
[/html]
</html>

Finally after 3 days.. I've sort it out Michael J, base on your guideline. After doing some reading on DOM, here's what I ammend;
1) Index.html;
[html]
[head]
[title][/title]
[script type="text/javascript"]
function popUp(URL,name) {
test = document.getElementById(name);
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=100,height=100,left = 462,top = 334');");
}
[/script][/head]
[body]
[form name="formname"]
[p][input type="text" id="font1"] [a href="javascript:void()" onclick="popUp('popme.html','font1')"]Link1[/a][/p]
[p][input type="text" id="font2"] [a href="javascript:void()" onclick="popUp('popme.html','font2')"]Link2[/a][/p]
[/form]
[/body]
[/html]2) popme.html;
[html]
[head]
[script type="text/javascript"]
function popParent(val) {
opener.test.value = val;
}
[/script]
[/head]
[body]
[p][a href="javascript:void()" onclick="popParent('Arial');"]Arial[/a][/p]
[p][a href="javascript:void()" onclick="popParent('Verdana');"]Verdana[/a][/p]
[/body]
[/html]Thanks Michael J.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |