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

Can I submit only Changed values of form ?

P: n/a
in other words, Can I make client side mod's before I submit a form and
Post ?

I guess its just a matter of cycling through the form elements and
setting value to null (or empty string) for those that did not Change (
using onChange ).

Jan 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
awebguynow wrote:
in other words, Can I make client side mod's before I submit a form and
Post ?
I understood the Subject better:

| Can I submit only Changed values of form

Yes, you can. Provided, that client-side scripting is enabled and the DOM
provides the necessary means. I would consider that use of client-side
scripting to be a Good Thing. However, you should not rely on it when
processing the submitted data server-side.
I guess its just a matter of cycling through the form elements and
setting value to null (or empty string) for those that did not Change (
using onChange ).


No, since `input' element's values are strings, setting them to null (type
`object') is likely to be unsuccessful, and setting the value to the empty
string will submit that name-value pair anyway as something matching
"[&?]name=", where `name' is the name of the `input' element.

What you can do is to iterate through the elements collection and where you
find an object that has the `value' and the `defaultValue' properties, and
the value of `value' is equal to the value of `defaultValue', you can
disable that the respective control. Quickhack:

<script type="text/javascript">
function submitChanged(f)
{
if (f && f.elements)
{
for (var i = f.elements.length; i--;)
{
var o = f.elements[i];
if (o.tagName.toLowerCase() == "input"
&& o.value == o.defaultValue
&& (!o.disabled || o.disabled.toLowerCase() == "disabled"))
{
if (!(o.disabled = true))
{
o.disabled = "disabled";
}
}
}
}
return true;
}
</script>

<form ... onsubmit="return submitChanged(this);">
...
</form>

The problem with this solution is if the Back feature of the UA is used, the
elements previously disabled on submit will probably stay disabled until
the document is reloaded.
HTH

PointedEars
Jan 5 '06 #2

P: n/a
Thank you. I will be using this, but wondered a few things. Is this
clause a workaround ?
o.disabled.toLowerCase() == "disabled")

I did read that early browsers did not have an
element.disabled property but it would be created if set.

Also, I've tried looping through the elements with limited success,
when using alert()
ie: alert( o.name ); // gets ignored

I actually wanted to see what the o.disabled property was set to.
If I'm missing something please let me know.

Jan 11 '06 #3

P: n/a
awebguynow wrote:
Thank you. I will be using this, but wondered a few things. Is this
clause a workaround ?
o.disabled.toLowerCase() == "disabled")
It is. It is also a way of making this method XHTML-proof.
I did read that early browsers did not have an
element.disabled property but it would be created if set.
That is the same to JS. As long as the object referred to by `o' exists,
if o.property exists (that is, it evaluates to a value different from
undefined) or evaluates to another true-value, !o.property evaluates to
`false'. If instead the property does not exist (that is, it evaluates to
`undefined') or has another false-value (including `undefined), !o.property
evaluates to `true'. The `!' operator converts its argument to boolean and
the operation evaluates to the boolean opposite of that (logical NOT).
Also, I've tried looping through the elements with limited success,
when using alert()
ie: alert( o.name ); // gets ignored
It does not get ignored here. Note that it matters where you call
(window.)alert(). If within the innermost (most-nested) block, it is only
called when assigning `true' to the disabled property was unsuccessful. If
within the next outer (less-nested) block, it is only called if the element
object represents a not-disabled `input' element which value was changed
aso.
I actually wanted to see what the o.disabled property was set to.
Then you will have to place the alert() call either directly in the loop's
block (before or after any IfStatement blocks it contains) or you have to
split the first IfExpression into two or more conditional blocks, depending
on the elements which `disabled' property you want to inspect:

if (x && y && z)
{
// ...
}

is semantically equal to

if (x)
{
if (y)
{
if (z)
{
// ...
}
}
}
If I'm missing something please let me know.


[x] done
HTH

PointedEars
Jan 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.