javascript - Check word length not working -
html
<form name="f1" action="feedback1.php" method="post" onsubmit="return isdatafilled();" > <table border="0" align="center" width="500px" style="max-width: 500px;" cellspacing="3" cellpadding="5" align="center"> <tr align="left"> <td width="25%"> enter subject </td> <td width="75%"><input type="text" name="subject" size="30" value="your subject" onclick="if(this.value=='your subject'){this.value=''}; this.style.backgroundcolor='#ccff99'" onblur="if(this.value==''){this.value='your subject'}; this.style.backgroundcolor='white'"/></td> </tr> <tr align="left"> <td> enter email<span style="color:#ff0000">*</span> </td> <td> <input type="text" name="email" size="30" value="example@mail.com" onclick="if(this.value=='example@mail.com'){this.value=''}; this.style.backgroundcolor='#ccff99'" onblur="if(this.value==''){this.value='example@mail.com'}; this.style.backgroundcolor='white'"/> </td> </tr> <tr align="left"> <td colspan="2"> enter message here<span style="color:#ff0000">*</span>: </td> </tr> <tr align="left"> <td colspan="2"> <textarea rows="10" cols="50" name="message" title="your message goes here" onclick= "if(this.value=='your message goes here'){this.value=''}; this.style.backgroundcolor='#ccff99'" onblur="if(this.value==''){this.value='your message goes here'}; this.style.backgroundcolor='white'" >your message goes here</textarea> </td> </tr> <tr> <td colspan="" align="right"> <input type="submit" value="send" name="b1" title="send message"/> </td> <td align="center"> <input type="reset" value="reset" name="reset" title="removes form data , fill again"/> </td> </tr> </table> </form
javascript
function isdatafilled() { if(document.forms['f1']['email'].value=='example@mail.com') { alert("no email address in email field!"); return false; } if(document.forms['f1']['message'].value=='your message goes here') { alert("no message in message field!"); return false; } return isemailcorrect(document.forms["f1"]["email"].value); return check_word_length(document.forms['f1']['message'].value, 20); } function isemailcorrect(f_email) { var x=f_email; var atpos=x.indexof("@"); var dotpos=x.lastindexof("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("not valid e-mail address"); return false; } } function check_word_length(text, over_size) { var word=0; var message=text; for(i=0;i<message.length;i++) { if(message.charat(i)==" ") { word=0; } else { word++; if(word>=over_size) { alert("too long text entered"); return false; } } } }
the function check_word_length(text, over_size)
not working. i'm confused because think code alright.
at end of isdatafilled
:
return isemailcorrect(document.forms["f1"]["email"].value); return check_word_length(document.forms['f1']['message'].value, 20);
the return
keyword exits current function; second return
in code never reached.
Comments
Post a Comment