eva21 Posted November 20, 2008 Share Posted November 20, 2008 I have a form, and there are 3 textboxes. Two of the textboxes the user enters a number, and the third one automatically multiplies them together. I wana make it so as soon as there is two valid numbers in these two textboxes, i want it added asap. Im not sure what to use onclick, onblur so any help is appreciative. <input type=text readonly size="3" MAXLENGTH="3" onclick="doCalc()" id="tot1" name="txt1" value=""> <input type=text readonly size="3" MAXLENGTH="3" onclick="doCalc()" id="tot1" name="txt2" value=""> <input type=text readonly size="3" MAXLENGTH="3" onclick="doCalc()" id="tot1" name="total" value=""> <script> function doCalc() { var txt1 = document.getElementById('txt1').value; var txt2 = document.getElementById('txt2').value; } </script> I know there isnt much for javascript, but i keep getting an error for the second line! Please help Link to comment https://forums.phpfreaks.com/topic/133534-need-help-with-javascript/ Share on other sites More sharing options...
rhodesa Posted November 20, 2008 Share Posted November 20, 2008 <input type=text size="3" MAXLENGTH="3" onkeyup="doCalc()" id="txt1" name="txt1" value=""> <input type=text size="3" MAXLENGTH="3" onkeyup="doCalc()" id="txt2" name="txt2" value=""> <input type=text readonly size="3" MAXLENGTH="3" id="total" name="total" value=""> <script> function doCalc() { document.getElementById('total').value = ''; var txt1 = parseInt(document.getElementById('txt1').value); var txt2 = parseInt(document.getElementById('txt2').value); if(txt1 && txt2){ document.getElementById('total').value = txt1 * txt2; } } </script> Link to comment https://forums.phpfreaks.com/topic/133534-need-help-with-javascript/#findComment-694563 Share on other sites More sharing options...
eva21 Posted November 20, 2008 Author Share Posted November 20, 2008 That gives me an error of... Runtime error has occured.... Error: 'document.getElementById(...)' is null or not an object Link to comment https://forums.phpfreaks.com/topic/133534-need-help-with-javascript/#findComment-694572 Share on other sites More sharing options...
eva21 Posted November 20, 2008 Author Share Posted November 20, 2008 Nvm, my mistake works perfectly...Thank you!!! Link to comment https://forums.phpfreaks.com/topic/133534-need-help-with-javascript/#findComment-694576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.