• Javascript "live text-field"
    5 replies, posted
Hi I'm trying to make a Form Field where the user enters a certain number and when he/she has entered a real number Javascript does some calculations on the number and then show the result on the right of the text-field. How can I achieve this? Thanks in advance :)
-snip- forgot what section i was in
Found out how to do it :) [php] <script type="text/javascript"> function is_int(value){ if((parseFloat(value) == parseInt(value)) && !isNaN(parseInt(value))){ return true; } else { return false; } } var you_have = 200; function changeText2(){ var userInput = document.getElementById('userInput').value; if(is_int(userInput) ){ if(userInput > you_have){ document.getElementById('boldStuff2').innerHTML = "Nope"; } else { document.getElementById('boldStuff2').innerHTML = userInput; } } else { document.getElementById('boldStuff2').innerHTML = "Nope"; } } </script> <b id='boldStuff2'></b><br> <input type='text' id='userInput' value='' onkeyup="changeText2()" /> [/php] This also checks if it's an integer (at least theoretically.. Doesn't actually work.)
Just use regex to see if it matches /^[0-9]+$/
What is the point of this? I'm assuming "you_have" is just for testing or something? turb_ is right, regex would work the best
Ajax?
Sorry, you need to Log In to post a reply to this thread.