Jump to content

validating number using javascript


jasmeet

Recommended Posts

<script type="text/javascript" language="javascript">

function checkempty()

{

  

   if(document.getElementById("title").value=="")

{

alert("Please enter title.");

document.getElementById("title").focus();

return false;

}


if((document.getElementById("word_count").value>"3000") || (document.getElementById("word_count").value<"400"))

{

alert("Please enter less than 3000 or more than 400 words.");

document.getElementById("word_count").focus();

return false;

}

 


  return true;

 

}

 

</script>

<form method="post" action="" name="my_form" id="theForm" onSubmit="return checkempty();">

<input size="80" id="title" type="text" name="title" value="" />

<textarea  id="word_count" name="word_count"></textarea>

<input type="submit" name="ok" value="submit"  />

 

 

 

/*********this script is not working in the above code **************/


if((document.getElementById("word_count").value>"3000") && (document.getElementById("word_count").value<"400"))

{

alert("Please enter less than 3000 or more than 400 words.");

document.getElementById("word_count").focus();

return false;

}

 

i am not good in javascript.. so please can any1 help me???? 

Link to comment
https://forums.phpfreaks.com/topic/280887-validating-number-using-javascript/
Share on other sites

It sounds like you're looking for length property:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length

 

If you're unsure how to use length, there are many resources here:

https://www.google.com/search?q=javascript+character+count+textarea

 

For future reference, JavaScript questions should be posted in the JavaScript forum:

http://forums.phpfreaks.com/forum/18-jvscript-help/

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.