writing values in form of other window

D

Danny Stolle

Hi all,

i can't figure this one out. from a main window i am opening another
window with a form in it. this form has an inputbox. from the main
window i want to write a value into this inputbox. so i need the handle
from the child window and write the value into this form.

i tried using:

var chWindow=window.open('form_with_input.htm');
var chForm=chWindow.document.forms[0];

chForm.name_of_element.value='test'; //didn't work.
chForm.id_of_element.value='test'; //didn't work.

both didn't work... can somebody help?
is it even possible what i am trying to do?

cheers, Danny
 
S

SCDeveloper

chWindow and chForm should be objects not variables. Try the following
example.

<script language=javascript>
function test() {
childW = window.open('form_wit­h_input.htm', 'childW',
'toolbar=no,directories=no,menubar=no,scrollbars=yes, location=no,
resizable=yes, WIDTH=600,HEIGHT=350');

if (childW != null) {
childW.document.open();
childW.document.bgColor = "ccffcc";
childW.document.write('<html><body><form name=form1><input
type=text name=ID value=000></form></body></html>');
chForm = childW.document.forms[0];
alert(chForm.ID.value);
chForm.ID.value="123456789";
alert(chForm.ID.value);

} else {
alert("Failed to open child window");
}
}
</script>

<a href='javascript:test()'>Test It!</a>


SCDeveloper
http://www.sharingcorner.com
 
D

Danny Stolle

SCDeveloper said:
chWindow and chForm should be objects not variables. Try the following
example.

<script language=javascript>
function test() {
childW = window.open('form_wit­h_input.htm', 'childW',
'toolbar=no,directories=no,menubar=no,scrollbars=yes, location=no,
resizable=yes, WIDTH=600,HEIGHT=350');

if (childW != null) {
childW.document.open();
childW.document.bgColor = "ccffcc";
childW.document.write('<html><body><form name=form1><input
type=text name=ID value=000></form></body></html>');
chForm = childW.document.forms[0];
alert(chForm.ID.value);
chForm.ID.value="123456789";
alert(chForm.ID.value);

} else {
alert("Failed to open child window");
}
}
</script>

<a href='javascript:test()'>Test It!</a>


SCDeveloper
http://www.sharingcorner.com

I understand the functionallity, much applied. Thanx!

Now would this technique be possible if you have an excisting website
(which is not yours) with a form in it, to write values in the
inputboxes as a prefill. or does the http/html-security prohibit this.

so for instance there is a website 'http://www.blabla.com' with a form
and several inputboxes. from my website i want to open this site in
which i've let have filled some values into these inputboxes. i tried to
but the javascript debugger console in mozilla tels me that the instance
form (chForm) has not properties.

this indicates that this is a security issue, am i right? i just thought
it would be another handle to a window-object.

Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,438
Messages
2,571,699
Members
48,796
Latest member
Greg L.
Top