By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,029 Members | 1,336 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,029 IT Pros & Developers. It's quick & easy.

Submit or not submit

P: n/a
If I declare in a form a field with an id but without a name it will not be
submitted.
However, once I assign a name to it it seems that I am not able to undo
this.

If I say in javascript...

MyForm.MyField.name='fíeld1';
MyForm.MyField.name='';

....the result is a fieldname of length zero that is still submitted.

Similarly the delete operator does not work. If I write...

delete MyForm.MyField.name;

.... I get an error message.

Are there ways to accomplish what I want?

Thanks,
Wim
Jul 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Wim Roffal wrote on 22 Nov 2003:
If I declare in a form a field with an id but without a name it
will not be submitted.


<snip>

If all you want to do is stop a control from being submitted, disable
it, like so:

document.forms['form_name'].elements['control_name'].disabled = true;

Mike

--
Michael Winter
M.******@blueyonder.co.uk.invalid (remove ".invalid" to reply)
Jul 20 '05 #2

P: n/a
"Wim Roffal" <wi*************@nospamm-planet.nl> writes:
If I declare in a form a field with an id but without a name it will not be
submitted.
Correct. According to the HTML specification, for a form control to be
successful (i.e., it will be submitted), it must have a control name.
However, once I assign a name to it it seems that I am not able to undo
this.

If I say in javascript...

MyForm.MyField.name='fíeld1';
MyForm.MyField.name='';

...the result is a fieldname of length zero that is still submitted.
It *is* a name property with a value that happens to be the empty
string. It's very much there.
Similarly the delete operator does not work. If I write...

delete MyForm.MyField.name;

... I get an error message.
That surprices me. That was what I would have suggested.
What error do you get?
Are there ways to accomplish what I want?


You can also try
document.forms.MyForm.elements.MyField.name = undefined;
It is not exactly the same as deleting the property,
but it is close.

(And that was a hint not to use the form ID as a global variable. It
won't work in, e.g., Mozilla/Netscape 6).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

P: n/a
Michael and Lasse, thanks for your replies:

"Michael Winter" <M.******@blueyonder.co.uk.invalid> schreef in bericht
news:Xn*******************************@193.38.113. 46...
Wim Roffal wrote on 22 Nov 2003:

document.forms['form_name'].elements['control_name'].disabled = true;
In this case I don't want the field disabled. The form is submitted in an
iframe, so I want to keep my page whole.

"Lasse Reichstein Nielsen" <lr*@hotpop.com> schreef in bericht
news:3c**********@hotpop.com... "Wim Roffal" <wi*************@nospamm-planet.nl> writes:
Similarly the delete operator does not work. If I write...

delete MyForm.MyField.name;

... I get an error message.
That surprices me. That was what I would have suggested.
What error do you get?


(translated form dutch) This action is not supported by this object.
Are there ways to accomplish what I want?
You can also try
document.forms.MyForm.elements.MyField.name = undefined;
It is not exactly the same as deleting the property,
but it is close.


I tried it. But if I do this I it will submit the field with fieldname
"undefined". (yes, I did not use quotes).
(And that was a hint not to use the form ID as a global variable. It
won't work in, e.g., Mozilla/Netscape 6).


Thanks for the tip. I am testing this in IE 5.5 now.

Wim
Jul 20 '05 #4

P: n/a

"Wim Roffal" <wi*************@nospamm-planet.nl> schreef in bericht
news:bp**********@reader10.wxs.nl...

You can also try
document.forms.MyForm.elements.MyField.name = undefined;
It is not exactly the same as deleting the property,
but it is close.


I tried it. But if I do this I it will submit the field with fieldname
"undefined". (yes, I did not use quotes).


What you can do, is remove the element by using the removeChild method:

function remove(f, e) {
var index = null;
for (var i = 0; i < f.childNodes.length; i++) {
if (f.childNodes.item(i).name == e) {
index = i;
break;
}
}
if (index === null) return;
return f.removeChild(f.childNodes.item(index));
}
....

<form method="get" action="">
<input type="hidden" name="element_a" value="1" />
<input type="hidden" name="element_b" value="1" />
<input type="button" value="remove element_a"
onclick="remove(form,'element_a')" />
<input type="button" value="remove element_b"
onclick="remove(form,'element_b')" />
</form>
JW

Jul 20 '05 #5

P: n/a

"Janwillem Borleffs" <jw@jwscripts.com> schreef in bericht
news:3f*********************@news.wanadoo.nl...

function remove(f, e) {
var index = null;
for (var i = 0; i < f.childNodes.length; i++) {
if (f.childNodes.item(i).name == e) {
index = i;
break;
}
}
if (index === null) return;
return f.removeChild(f.childNodes.item(index));
}
...


This looks nicer and does the same:

function remove(f, e) {
for (var i = 0; i < f.childNodes.length; i++) {
if (f.childNodes.item(i).name == e) {
return f.removeChild(f.childNodes.item(i));
}
}
}
JW

Jul 20 '05 #6

P: n/a
VK
I would say - Submit! :-)
And filter the submission on the server side (like all filelds with ""
value do not count).

On the client side you may use DOM:

with (document.myForm) {
removeChild(elements('myElement'));
}

Still not exactly what you want: it doesn't exclude an element from the
submission, it removes the element itself.
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.