Click here to Skip to main content
14,332,583 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi friends i'm trying to give min and max range values to multiple textbox but using id it is not possible help me with diff attributes

<script>


function checknumber(theid){
var mynumbervalue = document.getElementById(theid).value;
if (mynumbervalue > 65){

document.getElementById(theid).value = "0";

alert("Please try again. Values must be between 0-65. ...");
}

if(mynumbervalue < 0){

document.getElementById(theid).value = "0";

alert("Please try again. Values must be between 0-65 ...");
}
}    

</script>
<body>

<input id="thefirstnumbervalue" type="text"   önchange="checknumber('thefirstnumbervalue')" />

<input id="thesecondnumbervalue" type="text"   önchange="checknumber('thesecondnumbervalue')" />
Posted
Updated 17-Nov-13 20:29pm
v2
Comments
IpsitaMishra 18-Nov-13 2:31am
   
What is the issue you are getting here..
Arun-23 18-Nov-13 2:34am
   
.above code works fine but i need to give it for multiple textbox
Rate this:
Please Sign up or sign in to vote.

Solution 1

JavaScript:
<script type="text/javascript">
  function checknumber(txtid) {
        var mynumbervalue = parseFloat((txtid).value); 
        if (mynumbervalue > 65) {
                    txtid.value = "0";
                    alert("Please try again. Values must be between 0-65. ...");
                }
        if (theid.value < 0) {
                    txtid.value = "0";
                    alert("Please try again. Values must be between 0-65 ...");
                }
            }    
</script>

HTML Markup:
<input id="thefirstnumbervalue" type="text"   onchange="checknumber(this)" />
 
<input id="thesecondnumbervalue" type="text"   onchange="checknumber(this)" />
   
Comments
Arun-23 18-Nov-13 4:01am
   
thanks frnd..
Thanks7872 18-Nov-13 4:02am
   
You are welcome Arun.
Arun-23 18-Nov-13 4:59am
   
it works fine but i need to change one of the textbox for example if there 4 textbox it works for all 4 textbox but i need to fix the value of 25 to the 4th box how to do that plz help
Thanks7872 18-Nov-13 6:10am
   
Write separate function for that and call that function similarly as we have done in above code.
Rate this:
Please Sign up or sign in to vote.

Solution 2

<script type="text/javascript">
function checknumber(txt_id){
var mynumbervalue = txt_id.value;
if (mynumbervalue > 65){ 
txt_id.value = "0"; 
alert("Please try again.Values must be between 0-65. ...");
} 
if(mynumbervalue < 0){
txt_id.value = "0"; 
alert("Please try again. Values must be between 0-65 ...");
}
} 
 
    </script>


HTML

<input id="thefirstnumbervalue" type="text"  önchange="checknumber(this);" />
<input id="thesecondnumbervalue" type="text"  önchange="checknumber(this);" />
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100