onclick="trn.value='<?=$var?>'" it fills a textbox with the $var value, which is a number. The box should only hold a max of 99,999, therefore if $var is bigger than 99,999, 10,000,000 for example it would only put 99999 in the box. Can that be done somehow?
I'm a noob when it comes to js. But I can do it in PHP and assign the value to a new variable - not a bad idea at all.
Does it helps: <input type="text" id="number"><br> <input type="text" id="number2"><br> <a href="#" onClick="if(document.getElementById('number').value > 999999){alert('BIG NUMBER!');}else{document.getElementById('number2').value=document.getElementById('number').value;}">CLICK ME</a> Code (markup):
I think you got the wrong idea, but it is still helpful. $var = 10000; I do click on a button that has the onclick property and it inserts $var to a textbox <input type="text" name="trn"/> <input value="*" onclick="trn.value='<?=$var?>'" type="button"> But what I want to do is when $var exceeds 99999, it should only insert 99999 to the textbox, not a bigger number. So, if $var = 213453642145424; onclick will just insert 99999 to the textbox, and if it's smaller it enters the actual number.
Try this: <input type="text" id="number"><br> <input type="text" id="number2"><br> <a href="#" onClick="if(document.getElementById('number').value.length > 5){document.getElementById('number2').value = document.getElementById('number').value.substring(0, 5);}else{document.getElementById('number2').value=document.getElementById('number').value;}">CLICK ME</a> Code (markup):