Jump to content

Shall U Help Please:::


Maisara-WD

Recommended Posts

<html><head><script type="text/javascript">function validate_required(field,alerttxt){with (field){if (value==null||value=="")  {alert(alerttxt);return false;}else {return true}}}function validate_form(thisform){with (thisform){if (validate_required(email,"Email must be filled out!")==false)  {email.focus();return false;}}}</script></head><body><form action="submitpage.htm"onsubmit="return validate_form(this)"method="post">Email: <input type="text" name="email" size="30"><input type="submit" value="Submit"> </form></body></html>

About this validation txt guys..many things r too strange for me and I'm too stupid with jsplease (I'm so sorry) explain it from a to z and I'll comment with questions to get hte whole tsk and thank u vrrrrryyyyyyyyy much

Link to comment
Share on other sites

onsubmit="return validate_form(this)"I'm sure you get this part, but let's say it anyway. We're calling a function named validate_form(). We are passing it a reference to the form itself, using the 'this' keyword. validate_form() will return true or false. If it returns false, the form will not submit.with (thisform)Now we're in the validate_form() function. 'thisform' is the same reference to the form that we passed it above. I guess the 'with' keyword surprised you. It allows you to name an object (an array, a javascript object, a page element, whatever) and then refer to members of the object without having to name the object itself every time. So that when we get to this next part . . . validate_required(email,"Email must be filled out!"). . . 'email' actually means 'thisform.email', which means the input named 'email' inside the form. I think the with construction is silly, myself, and I never use it.with (field){if (value==null||value=="")We're in the validate_required() function now. Remember we passed that function a reference to the email input, which we called 'email'. This function calls that 'field', since it can be used to validate any field, not just one called 'email. So now, the variable 'field' is a reference to thisform.email . Because that refers to a text input in the form, it has a value property. Since we are using the with construction again, the variable called 'value' means 'field.value' , which means thisform.email.value -- that is, whatever the user types into the email input in the form.You can figure out the rest I believe?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...