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???? 

Edited by jasmeet
Link to comment
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/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.