Arif Arif - 3 months ago 10
Javascript Question

call 2 functions onClick event

I have a text field with PLUS + button to increase textfield value, at the same time i want the limit of (0 - 100). I dont want any one increase value more then 100 or less then 0.

I try below code which only work for add function

<script type="text/javascript">
function add(){
document.getElementById("name").value++;
}
function limit(){
document.getElementById('name').value;
if(this.value > 200){
this.value = 200;
}
if(this.value < 10){
this.value = 10;
}
}
</script>

<form name="quiz" >
<input type='text' name='name' id='name'/>
<input type='button' name='plus' onclick="add();limit();" value='+'/>
</form>


And is it possible to increase value by 5 i.e instead of value++ can we use value+5 (i try it but not working)

Answer
    function add(){
x=document.getElementById("name").value;
x=Number(x);
x=x+5
document.getElementById("name").value=x;
}

    function limit(){
x=document.getElementById("name").value;
x=Number(x);
      if(x > 100){
           document.getElementById("name").value = 100;
      }
      if(x < 50){
           document.getElementById("name").value = 0;
      }