Connecting Tech Pros Worldwide Help | Site Map

Re: Newbie problem checking input fields

 
LinkBack Thread Tools Search this Thread
  #1  
Old August 26th, 2008, 07:15 PM
SAM
Guest
 
Posts: n/a
Default Re: Newbie problem checking input fields

DaveForgotHisEngineering a écrit :
Quote:
I suspect that the function isEmpty() is not being run
when the user clicks submit. Thanks in advance for any suggestions
you can offer.
Quote:
function isEmpty()
{
var a=document.getElementsByName("Name:").value.length ;
var b=document.getElementsByName("Email:").value.lengt h;
var c=document.getElementsByName("Telephone:").value.l ength;
var d=document.getElementsByName("City:").value.length ;
var e=document.getElementsByName("State:").value.lengt h;
var f=document.getElementsByName("Comments").value.len gth;
// and where do you look if the elements's values are empty ?

var a=document.getElementsByName("Name:").value.length >0;
var b=document.getElementsByName("Email:").value.lengt h>0;
var c=document.getElementsByName("Telephone:").value.l ength>0;
var d=document.getElementsByName("City:").value.length >0;
var e=document.getElementsByName("State:").value.lengt h>0;
var f=document.getElementsByName("Comments").value.len gth>0;
Quote:
if(!a || !b || !c || !d || !e || !f)
{
alert("Please fill in all of the fields and comments");
return false;
Quote:
}
return true;
Quote:
}
</script>
.
.
.
.
(Code snippet by submit button)
<form onsubmit="return isEmpty()" action="blah....">
Quote:
<h2>Please include a short story about your restaurant:</h2>
<p class="style1">
<label>
<textarea name="Comments" cols="60" rows="10"></textarea>
</label>
</p>
<p>&nbsp;</p>
<p>
<input type="submit" name="Submit" value="Submit"
onclick-"isEmpty()"/>
<input type="submit" />
Quote:
</p>
</form>


--
sm

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.