Click here to Skip to main content
15,868,306 members
Please Sign up or sign in to vote.
1.00/5 (1 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

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

JavaScript:
C#
<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:
C#
<input id="thefirstnumbervalue" type="text"   onchange="checknumber(this)" />
 
<input id="thesecondnumbervalue" type="text"   onchange="checknumber(this)" />
 
Share this answer
 
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.
HTML
<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

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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900