slyte33 Posted October 31, 2009 Share Posted October 31, 2009 This is for my text-based rpg game. So let's say i had this: <form method="post" action="guild_payout.php"> <input type="text" name="amount" id="amount" onkeyup="showMsg()" value="" size="15"/> <input type="submit" name="submit" value="Submit"> </form> I have it to display the amount typed correctly, but what I want to do is divide what was typed by 5, but I can't seem to get it to work right. I have this: <script type="text/javascript"> function showMsg(){ var userInput = document.getElementById('amount').value; document.getElementById('userMsg').innerHTML = userInput; } </script> <div id=userMsg></div> So it does display the amount typed, but ofcourse you can't divide a "div" tag by 5, correct? If i'm wrong, then how But if im right, how else? Any feedback is very much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/179702-solved-displaying-a-textbox-value-as-typing-divide-it-by-5/ Share on other sites More sharing options...
Stuie_b Posted October 31, 2009 Share Posted October 31, 2009 Why cant you divide by 5? your right a div cant be used in math but your putting the value of the text box into a variable and as such you can do pritty much anything with it... try the following <script type="text/javascript"> function showMsg(){ var userInput = document.getElementById('amount').value; document.getElementById('userMsg').innerHTML = userInput / 5; } </script> <div id=userMsg></div> <form method="post" action="guild_payout.php"> <input type="text" name="amount" id="amount" onkeyup="showMsg()" value="" size="15"/> <input type="submit" name="submit" value="Submit"> </form> what you will have todo is make sure that only numbers are entered and not text other wise js will return NaN Stuie Quote Link to comment https://forums.phpfreaks.com/topic/179702-solved-displaying-a-textbox-value-as-typing-divide-it-by-5/#findComment-948159 Share on other sites More sharing options...
slyte33 Posted October 31, 2009 Author Share Posted October 31, 2009 Ahh something so simple, but effective. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/179702-solved-displaying-a-textbox-value-as-typing-divide-it-by-5/#findComment-948160 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.