Computing.Net > Forums > Web Development > Javascript: How To..

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Javascript: How To..

Reply to Message Icon

Name: mie2com
Date: December 3, 2006 at 23:34:11 Pacific
OS: WinXP
CPU/Ram: Pentium III
Product: Sony
Comment:

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>



Sponsored Link
Ads by Google

Response Number 1
Name: Michael J (by mjdamato)
Date: December 4, 2006 at 22:04:44 Pacific
Reply:

Using your previous example:

function font() {
document.formname.font_type.value = "Arial";
document.formname.field2.value = "Arial";
document.formname.field3.value = "Arial";

}

Michael J


0

Response Number 2
Name: mie2com
Date: December 4, 2006 at 23:52:55 Pacific
Reply:

Thanks for your reply Michael. I've try that but it pass the value to all input at the same time.


0

Response Number 3
Name: mie2com
Date: December 5, 2006 at 00:23:26 Pacific
Reply:

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.


0

Response Number 4
Name: Michael J (by mjdamato)
Date: December 5, 2006 at 06:48:19 Pacific
Reply:

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


0

Response Number 5
Name: mie2com
Date: December 5, 2006 at 16:42:08 Pacific
Reply:

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.


0

Related Posts

See More



Response Number 6
Name: Michael J (by mjdamato)
Date: December 5, 2006 at 23:10:44 Pacific
Reply:

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


0

Response Number 7
Name: mie2com
Date: December 6, 2006 at 01:06:57 Pacific
Reply:

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>


0

Response Number 8
Name: mie2com
Date: December 6, 2006 at 01:59:44 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: Javascript: How To..

How to make online Reseller Website www.computing.net/answers/webdevel/how-to-make-online-reseller-website/2727.html

How to set 80kb or 20 cookies ? www.computing.net/answers/webdevel/how-to-set-80kb-or-20-cookies-/1133.html

How to do this? www.computing.net/answers/webdevel/how-to-do-this/3133.html