473,395 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

createElement question

Okay, I think I can simplify my earlier question.

If I have a html form

[HTML]<form>
<input type="button" value="More" onclick="addField(this.form;return false; )">
</form>[/HTML]

and assuming this code could not be changed.
Now addField is defined:

Expand|Select|Wrap|Line Numbers
  1. function addField(form)
  2. {
  3.   document.createElement('<FORM ACTION="HTTP://cgi-bin/whatever.cgi" METHOD="POST">');
  4.   document.createElement("<INPUT TYPE='TEXT' NAME='acc' VALUE='777'>");
  5.   form.submit();
  6. }
How do I modify the createElement statement so that the new elements are part of form? Or how to modify form.submit() so that what it submits is based on the new form elements?

Thanks
Garth
Jan 28 '07 #1
2 1279
pronerd
392 Expert 256MB
First off I am guessing "addField(this.form;return false; )" should be "addField(this.form); return false;" since your addField method only defines on argument to passed to it, and ";" are not used in method calls, and you cant pass return commands in a method call.

Secondly I think the return false is automatically blocking your submit

Third you already have an HTML form tag so why are you creating another one? It is not legal to have a form tag nested inside another form tag. Also you are creating a new HTML opening form tag but not a closing one.

Fourth you are submitting the original form tag that does not have an action assositate with it so I can not submit anything.

Fifth you are missing a lot of steps to create an element. Have you googled for examples? They are everywhere. It should be something like


[HTML]<form id="formToSubmit" action="someURLHERE" >
<input type="button" value="More" onclick="addField()">
</form>

<script>
function addField(form) {
var formElement = document.getElementById("formToSubmit");
var newField = document.document.createElement('input');
newField.setAttribute('type','text');
newField.setAttribute('name','acc');
newField.setAttribute('value','777');
formElement.appendChild( newField );
formElement.submit();
}
</script>[/HTML]
Jan 28 '07 #2
acoder
16,027 Expert Mod 8TB
Are you sure you cannot edit the original form? It contains the error that pronerd mentioned above: you'll need to remove the return false;

Other than that, you can work with that code using, e.g. pronerd's code, except you can use the passed form value to access the HTML DOM for the form tag, e.g.
Expand|Select|Wrap|Line Numbers
  1. form.action='youractionpage.php';
See this link for more information.
Jan 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
2
by: kie | last post by:
hello, when i create elements and want to assign events to them, i have realised that if the function assigned to that element has no parameters, then the parent node values can be attained. ...
4
by: sg_maat | last post by:
I have a little problem with createElement(and msie). I was experimenting a bit with createElement and made the following script: <script> var tmp = document.createElement("div");...
9
by: Kim | last post by:
Hi I'm trying to do something like this. for(i=0; i<5; i++){ var theData = document.createElement('a'); theData.onmouseover = function() { return get(i);} ... ... }
7
by: bayfaulkscatering | last post by:
I'm definitely not new to JS, but for the life of me, I can't figure this one out. Here's basically what I'm doing: function foo() { alert(this); } span = document.createElement('span'); a...
3
by: Arpan | last post by:
Using DOM, this is how I am appending data to an existing XML file which is named AppendData.xml (the root element of AppendData.xml is <ProductList>): <script runat="server"> Sub...
3
by: acecraig100 | last post by:
I am fairly new to Javascript. I have a form that users fill out to enter an animal to exhibit at a fair. Because we have no way of knowing, how many animals a user may enter, I created a table...
7
by: Tarik Monem | last post by:
Why am I having so much trouble with using DOM in IE & Opera to create, then remove an Object & Embedded element? Here's the code that works in Firefox (Mac/Win/Linux) and Safari, but not on IE or...
23
by: vunet | last post by:
It is recommended by some sources I found to create IFrames in IE using document.createElement('<iframe src="#">') instead of document.createElement('iframe'). Why and what browser versions to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.