Hi all --
I'm trying to create a hidden form in the document using only
Javascript -- I don't know what form I want until the user clicks a
button --
I tried the following code, which does create the objects in the
document hierarchy; the problem is it does not insert the HIDDEN field
into the list of form elements[].
<HTML>
<HEAD>
<SCRIPT LANG=javascript >
// recreate the following HTML form:
// <form method="GET" action="http://search.yahoo.co m/bin/search">
// <input type="text" name="p" value="" size=35>
// </form>
function submitToYahoo() {
var first = true;
if (first) {
alert("creating form");
var yahooForm = document.create Element("Form") ;
yahooForm.name = "yForm"
yahooForm.actio n = "http://search.yahoo.co m/bin/search"
yahooForm.metho d = "GET";
yahooFormInput = document.create Element("Hidden ");
yahooFormInput. name = "p";
yahooForm.appen dChild(yahooFor mInput);
document.body.a ppendChild(yaho oForm);
first = false;
}
alert(document. forms.length); // I get 2 here
alert(document. forms[1].name); // I get "yForm", as expected
alert(document. forms["yForm"].elements.lengt h); // I get 0, sadly
alert(document. forms["yForm"].childNodes.len gth); // I get 1, as expected
alert(document. forms["yForm"].childNodes[0].name); // I get "p", as expected
document.forms["yForm"].elements[0].value =
document.forms["theVisible "].input1.value; // runtime error: elements[0] has no properties
document.forms["yForm"].submit();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=white>
<form id=theVisible> <input type=text id="input1" size=35 onBlur=submitTo Yahoo()></form>
</BODY>
</HTML>
Any ideas?
Thanks in advance,
Bob
I'm trying to create a hidden form in the document using only
Javascript -- I don't know what form I want until the user clicks a
button --
I tried the following code, which does create the objects in the
document hierarchy; the problem is it does not insert the HIDDEN field
into the list of form elements[].
<HTML>
<HEAD>
<SCRIPT LANG=javascript >
// recreate the following HTML form:
// <form method="GET" action="http://search.yahoo.co m/bin/search">
// <input type="text" name="p" value="" size=35>
// </form>
function submitToYahoo() {
var first = true;
if (first) {
alert("creating form");
var yahooForm = document.create Element("Form") ;
yahooForm.name = "yForm"
yahooForm.actio n = "http://search.yahoo.co m/bin/search"
yahooForm.metho d = "GET";
yahooFormInput = document.create Element("Hidden ");
yahooFormInput. name = "p";
yahooForm.appen dChild(yahooFor mInput);
document.body.a ppendChild(yaho oForm);
first = false;
}
alert(document. forms.length); // I get 2 here
alert(document. forms[1].name); // I get "yForm", as expected
alert(document. forms["yForm"].elements.lengt h); // I get 0, sadly
alert(document. forms["yForm"].childNodes.len gth); // I get 1, as expected
alert(document. forms["yForm"].childNodes[0].name); // I get "p", as expected
document.forms["yForm"].elements[0].value =
document.forms["theVisible "].input1.value; // runtime error: elements[0] has no properties
document.forms["yForm"].submit();
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR=white>
<form id=theVisible> <input type=text id="input1" size=35 onBlur=submitTo Yahoo()></form>
</BODY>
</HTML>
Any ideas?
Thanks in advance,
Bob
Comment