473,394 Members | 1,699 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,394 software developers and data experts.

Can I submit only Changed values of form ?

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
3 6035
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: js | last post by:
Hi all. Is there a way to 'force' a submit on a form with out actually allowing the user to press a button ? For example... step1: A from is filled out by a user, then they click the submit...
15
by: Mattia | last post by:
Hi! I have a <form> that can be submitted thruogh three buttons and I need to tell witch one was pressed when the form was submitted. I now do it with 3 <input type="submit" name="..."...
6
by: charlie_M | last post by:
I figured out via various help from this forum... EXAMPLE: onClick="document.forms.MYBUTTON.value='SIMPLE';document.forms.submit()" In my CGI I see "MYBUTTON" = "SIMPLE" and this works...
2
by: Jim Duncan | last post by:
How can I make a client-side javascript form.submit() look enough like a postback that the browser back button will not show the previous state of the form and instead go to the previous page? I...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
4
by: d3vkit | last post by:
I have a form on my page, and some javascript which uses ajax to submit the form, and then opens the new page in a div using ajax so there is no refresh. This works fine. But the problem is this: all...
16
by: sreemati | last post by:
Hi everyone, This is the scenario: I have two button - Submit and Reset Submit is used for validation and after validation is passed it passes it to another form to enter into database. ...
4
by: vunet | last post by:
Hello, My HTML form submits some values to a hidden iframe. However, this is done for file upload fields only. After file uploading is finished I am using this form to submit all other data...
5
by: Rider | last post by:
Hi All, Here is the reason why i ak asking for ur help. I have a edit form in which the values already stored in DB are populated. User can edit some or all the values in the form. then he...
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: 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...
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?
1
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...
0
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...
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
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.