html - Can't get javascript to calculate string length -
i have form 1 below, , i'm trying calculate string length of inserted user value javascript.
<form class="newcomment" method="post" id="formcourse1" name="commentadd"> <textarea class="scrollwelcome" id="text" rows="4" cols="65" name="course1" placeholder="ciao <?php print($name); ?>! inserisci qui il tuo commento"></textarea> <input type="submit" id="button" name="submit" value="manda"> i've been trying code can't work, won't go if statement. help? thank you
function commentlength() { address = oform.elements["course1"].value; var length = address.length; if (length==1) { document.getelementbyid("lengtherror").innerhtml = "one character"; } if (length<5 & length>1) { document.getelementbyid("lengtherror").innerhtml = "several characters"; } return false; }
you may try (length<5 && length>1) (two ampersands) in if clause.
Comments
Post a Comment