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.com/bin/search">
// <input type="text" name="p" value="" size=35>
// </form>
function submitToYahoo() {
var first = true;
if (first) {
alert("creating form");
var yahooForm = document.createElement("Form");
yahooForm.name = "yForm"
yahooForm.action = "http://search.yahoo.com/bin/search"
yahooForm.method = "GET";
yahooFormInput = document.createElement("Hidden");
yahooFormInput.name = "p";
yahooForm.appendChild(yahooFormInput);
document.body.appendChild(yahooForm);
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.length); // I get 0, sadly
alert(document.forms["yForm"].childNodes.length); // 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=submitToYahoo()></form>
</BODY>
</HTML>
Any ideas?
Thanks in advance,
Bob 7 7777
Bob Nolty <no***@spiritvideo.com> writes: yahooFormInput = document.createElement("Hidden");
You mean
yahooFormInput = document.createElement("input");
yahooFormInput.type = "hidden";
There is no element called "hidden".
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen <lr*@hotpop.com> writes: You mean yahooFormInput = document.createElement("input"); yahooFormInput.type = "hidden"; There is no element called "hidden".
You are right! I was confused because there *is* a class called
Hidden which inherits from Input (documented in the Client-Side
JavaScript Reference in O'Reilly's "javascript : The Definitive Guide,
4th Edition"); however, it appears that "Hidden" is not a proper
argument to createElement (it doesn't throw an error, though :-/ )
Thanks for getting me back on the right track,
Bob
what exactly should your page do? the solution seems a little complicated!
"Bob Nolty" <no***@spiritvideo.com> wrote in message
news:m3************@spiritvideo.com... 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.com/bin/search"> // <input type="text" name="p" value="" size=35> // </form>
function submitToYahoo() { var first = true; if (first) { alert("creating form"); var yahooForm = document.createElement("Form"); yahooForm.name = "yForm" yahooForm.action = "http://search.yahoo.com/bin/search" yahooForm.method = "GET"; yahooFormInput = document.createElement("Hidden"); yahooFormInput.name = "p"; yahooForm.appendChild(yahooFormInput); document.body.appendChild(yahooForm);
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.length); // I get 0, sadly alert(document.forms["yForm"].childNodes.length); // 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=submitToYahoo()></form> </BODY> </HTML>
Any ideas?
Thanks in advance, Bob
Bob Nolty <no***@spiritvideo.com> wrote in message news:<m3************@spiritvideo.com>... Lasse Reichstein Nielsen <lr*@hotpop.com> writes:
You mean yahooFormInput = document.createElement("input"); yahooFormInput.type = "hidden"; There is no element called "hidden".
You are right! I was confused because there *is* a class called Hidden which inherits from Input (documented in the Client-Side JavaScript Reference in O'Reilly's "javascript: The Definitive Guide, 4th Edition"); however, it appears that "Hidden" is not a proper argument to createElement (it doesn't throw an error, though :-/ )
Thanks for getting me back on the right track, Bob
In my quick test, using IE6, document.forms['form_name'] does not
return the form. document.forms['form_id'] does return the form.
FWIW
"Greg" <gd*******@hotmail.com> wrote : In my quick test, using IE6, document.forms['form_name'] does not return the form. document.forms['form_id'] does return the form.
Quick test indeed, you have to slow down ;-).
Look at this:
<form name="fname" id="fid">
</form>
<script>
alert(document.forms['fname'].tagName);
alert(document.forms['fid'].tagName)
</script>
Vjekoslav Begovic wrote: "Greg" <gd*******@hotmail.com> wrote :
In my quick test, using IE6, document.forms['form_name'] does not return the form. document.forms['form_id'] does return the form.
Quick test indeed, you have to slow down ;-).
Look at this:
<form name="fname" id="fid">
</form> <script> alert(document.forms['fname'].tagName); alert(document.forms['fid'].tagName) </script>
Nice code, but to come up to speed you would need to match
a) Bob's problem code,
b) what Greg didn't say :)
Anyway, /incredible/ as it may seem, there seems to be a bug in IE.
If a child element of a form is inserted using DOM methods, the child
must be given an *id* attribute for it to be also made a named property
of the Form object under IE. It will go into the form's elements
collection regardless.
So right after
<unsnip>
yahooFormInput.name = "p";
</unsnip>
try adding
yahooFormInput.id = "p";
Doesn't work for radio input groups unfortunately, but innerHTML can be
used to programatically insert HTML for these.
HTH,
Dom
---
never knowingly make a miss-take.
"Dom Leonard" <do*************@senet.andthis.com.au> wrote in message
news:fM*******************@nnrp1.ozemail.com.au... Vjekoslav Begovic wrote:
"Greg" <gd*******@hotmail.com> wrote :
In my quick test, using IE6, document.forms['form_name'] does not return the form. document.forms['form_id'] does return the form.
Quick test indeed, you have to slow down ;-).
Look at this:
<form name="fname" id="fid">
</form> <script> alert(document.forms['fname'].tagName); alert(document.forms['fid'].tagName) </script>
Nice code, but to come up to speed you would need to match a) Bob's problem code, b) what Greg didn't say :)
Uppps. I need to be much more careful, sorry Greg.
So right after <unsnip> yahooFormInput.name = "p"; </unsnip> try adding yahooFormInput.id = "p";
If the form has the id, that is not nessesary.
Regards,
Vjekoslav This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sumithradevi |
last post by:
Hello Friends,
I have two forms(form1 and form2) on my html page.
question1 : can i access form 1 variables in form 2?. if so how?
question 2: when form2 action is saveci.jsp . can i access...
|
by: Dave F. |
last post by:
Is it possible to access the value of a radio button or change a radio
button to enabled/disabled without using the forms tags<FORM></FORM>? In
other words is the forms tag required for these...
|
by: Paul M |
last post by:
Hi,
I've got a recordset consisting of many records (anything up to 250)
which currently loops to populate a form in each iteration. I need to
post the form to an external URL on each loop, or...
|
by: Zak McGregor |
last post by:
Hi all
Are there any good solutions to aligning form field names and input boxes
without resorting to tables? I am struggling to do this nicely at the
moment.
Thanks
Ciao
Zak
|
by: ALthePal |
last post by:
Hi,
I'm not sure if we are able to or even how to loop through the web forms in
a VB.NET project during design time. In MSAccess we are able to go through
the database -> forms collection and...
|
by: ~~~ .NET Ed ~~~ |
last post by:
Hi,
As you all know when an ASP.NET web form is created that will include
web controls and such, it contains a
FORM that that identifies the web form and its containing controls.
Well, I have a...
|
by: thersitz |
last post by:
I can't seem to get my html form to submit properly from within a web form.
Here's my form tag syntax and some delivery hidden fields.
<form id="myForm"...
|
by: mosesdinakaran |
last post by:
Hi All,
I need a small clarification in submitting the forms, Ur
suggestions please.
In a page I have two form and also two submit butons.
(ie)
|
by: Rory Becker |
last post by:
Having now created a Custom MembershipProvider that seems to work correctly
with my Logon and ChangePassword controls, I am, as they say, a happy bunny.
The next stange is to move on to the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |