Guest FirefoxRocks Posted March 26, 2007 Share Posted March 26, 2007 Doesn't work for me. Maybe I have a wrong function? <script type="text/javascript">function change(){var c=document.getElementById("pages").value/3;document.getElementById.("credits").value=Math.round(c)}</script> The input buttons: <td><input type="text" size="2" maxlength="2" id="pages" name="pages" onkeydown="change()" />|--> It will cost you <input type="text" size="2" maxlength="2" id="credits" name="credits" /> credits.</td> I tried putting the onkeydown="change()" into different input also and tried a different event. No luck. Help is needed :| Link to comment Share on other sites More sharing options...
pulpfiction Posted March 27, 2007 Share Posted March 27, 2007 Remove period [.] from below statement...document.getElementById.("credits").value=Math.round© Link to comment Share on other sites More sharing options...
pulpfiction Posted March 27, 2007 Share Posted March 27, 2007 If you are using onkeydown event, then the first time when a number is pressed, the value in textbox is null. instead use onkeyup event. try code below. <script type="text/javascript">function change(num){var c;c=num/3;document.getElementById("credits").value=Math.round(c)}</script><input type="text" size="2" maxlength="2" id="pages" name="pages" onkeyup="change(this.value)" />|--> It will cost you <input type="text" size="2" maxlength="2" id="credits" name="credits" /> Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted March 27, 2007 Share Posted March 27, 2007 If you are using onkeydown event, then the first time when a number is pressed, the value in textbox is null. instead use onkeyup event. try code below.<script type="text/javascript">function change(num){var c;c=num/3;document.getElementById("credits").value=Math.round(c)}</script><input type="text" size="2" maxlength="2" id="pages" name="pages" onkeyup="change(this.value)" />|--> It will cost you <input type="text" size="2" maxlength="2" id="credits" name="credits" /> It works! Thank you very much! As you can see, I'm not good at JavaScript Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now