We need a solution to such a problem, how to make it possible to enter numbers from 1 to 4 in the input type="text" field. Numbers 5,6, etc. not valid.

Here's another question! If you make the buttons increase or decrease the number, because then the script does not work.

Here are the buttons:

  <a onClick="document.getElementById('count').value++; return true;">Up</a> <a onClick="document.getElementById('count').value--; return true;">Down</a> 
  • I answered all your questions! - Rules
  • Then you need on free-lance.ru - Rules
  • There they will break a large price. OK thanks. - AubakirovAlex
  • Here's another question! If you make an increase or decrease in quantity, because then the script does not work. Here are the <a onClick="document.getElementById('count').value++; return true;"> Up </a> <a onClick = "document.getElementById ('count'). Value--; return true;" > Down </a> - AubakirovAlex 2:55 pm
  • Who put me a minus and why !!? !! - Rules

1 answer 1

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Имя страницы</title> </head> <body> <input type="text" id="inp1" onKeyUp="kup(1,4,'inp1')" value=""> <input type="text" id="inp2" onKeyUp="kup(6,9,'inp2')" value=""> </body> <script> function kup(min,max,id){ inpt=document.getElementById(id); val=inpt.value; buf=new Array(); for(var i=0;i<val.length;i++){ buf[i]=val[i]; } flag=true; for(var i=0;i<val.length;i++){ if(parseInt(buf[i])>max||parseInt(buf[i])<min){ buf[i]=""; flag=false; } } inpt.value=buf.join(""); if(!flag){alert("Допустимое значение от "+min+" до "+max+"!");} } </script> </html> 
  • one
    Click on the check mark next to the answer to accept it! - Rules
  • Now I will change the answer - Rules
  • Here ... understand how it works? - Rules
  • Thank. And you can implement this chip. Suppose when you enter the number 5, there was a hint "Valid value from 1 to 4" PS: You did not work with the formcalc form for Joomla? What I'm doing now is just that I came up with such a solution. And ideally, there should be a field for entering quantities, and when the numbers in this field appear from 5 to 9, a discount of 5% should be taken away. - AubakirovAlex
  • No, I’m writing everything myself I don’t use CMS, but I’m giving you a pop-up prompt. I’ll change the answer .. - Rules