Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for form update values

Status
Not open for further replies.

evergreean43

Technical User
May 25, 2006
165
US
I have an Update form where I check if any values were changed after someone submits the form.

If no values changed then message pops up and says:
You did not update any information for this Form.
The form will only go to the action page if a value is changed.

It works great but cant get it to work after I add a validation check on select element which has only one value selection choice (not multiple):


Here is my validation check:
Code:
e=myform.elements;
for (i;i< e.length;i++) 
{
    if ((e[i].type == 'text') || (e[i].type == 'textarea') || (e[i].type == 'select')) 
    {
       if (e[i].value != e[i].defaultValue) 
       {
          return true;
       }
     }
}
alert("You did not update any information for this Form.");
return false;

The above checks for text and textarea elements only for changes and wont work with select element.

My select part of the form:
Code:
<form....
<select name = "myname">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
..
</form>
 
i don't think defaultValue is an attribute of the select field. instead try loading an array with all of your default selectedIndexes when the page loads, then comparing against them.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks,

My attempt with loading into an array doesnt seem to work because it doesnt validate the form and continues to action page if I dont change any values. Please advise what I need to change because I have tried many versions and it still not working.

Code:
e=myform.elements;
j = 0;
myfieldValue = '';
myselectValue = '';
for (i;i< e.length;i++) 
{
   if ((e[i].type == 'text') || (e[i].type == 'textarea') || (e[i].type == 'select')) 
    {
       if (e[i].value != e[i].defaultValue) 
       {
          return true;
       }
    }

[b]
if(e[i].type == 'select-one')
   {
      while(myfieldValue = myselectValue.options[j++])
      {
         if ((myfieldValue.selected && myfieldValue.defaultSelected) || (!myfieldValue.selected && myfieldValue.defaultSelected))
         {
	    return true;
         }
      }
   }
[/b]
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top