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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for update before submitting

Status
Not open for further replies.

evergreean43

Technical User
May 25, 2006
165
US
I am trying to check my text and textarea fields on my update form to make sure a field value was changed before going to action page. If none were changed and someone hits submit button it should pop up message saying: You did not update any information for this form submit.

Please advise because my below attempt not working where it pops up the message everytime I submit. I assume my problem is in the myField.type conditions but not sure:

Code:
function chkUpdate(myedit)
{
var myField, myValue, i, j; 


i = 0
while (myField = myedit.elements[i++]) 
{
		
   if((myField.type == 'text') || (myField.type == 'textarea'))
    {
       if (myField.value != myField.defaultValue) 
       {
          return theChange(myedit);
       }
       break;
     }
}
alert("You did not update any information for this form submit.");
return false;
}

function theChange(myedit) 
{
	//info was edited, go to action page
	return true;
}
 
interesting. is that REALLY your theChange function? try something like this:

Code:
function chkUpdate(myedit) {
    var e = myedit.elements;
    for ( var i = 0; i < e.length; i++ ) {
        if ( e[i].type == 'text') || e[i].type == 'textarea') {
            if ( e[i].value != e[i].defaultValue ) {
                return true;
            }
        }
    }
    alert("You did not update any information for this form submit.");
    return false;
}

this is assuming you're calling the function from the form's onsubmit event.



*cLFlaVA
----------------------------
[tt]"quote goes here"[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks it works great for IE and most of the time in Netscape 7.

If my Netscape 7 textarea has multiple line values it doesnt validate. Is this because of an issue with Netscape 7 textarea element defaultValue? Is there a way to fix that in Netscape 7 where I assume it has something to do with newline character??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top