EnriqueI Posted September 4, 2008 Share Posted September 4, 2008 How would I have two fields in a form multiply each other instantaneously inputing the result into a third field, that the user can not edit? I can do this with javascript, but I need a button to trigger it. Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/ Share on other sites More sharing options...
tibberous Posted September 4, 2008 Share Posted September 4, 2008 Fire it off the on change event of the inputs, not the buttons click event. Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/#findComment-633331 Share on other sites More sharing options...
EnriqueI Posted September 4, 2008 Author Share Posted September 4, 2008 Fire it off the on change event of the inputs, not the buttons click event. Change the javascript to calculate on change of the inputs? How would I do that? (sorry, I'm a newbie to anything web development... or coding in general.) Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/#findComment-633421 Share on other sites More sharing options...
tibberous Posted September 4, 2008 Share Posted September 4, 2008 <script> function update(){ document.getElementById('answer').value = document.getElementById('f1').value * document.getElementById('f2').value; } </script> <input id='f2' type='text' onchange='update()'><input id='f1' type='text' onchange='update()'><input id='answer' type='text'> Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/#findComment-633613 Share on other sites More sharing options...
EnriqueI Posted September 5, 2008 Author Share Posted September 5, 2008 <script> function update(){ document.getElementById('answer').value = document.getElementById('f1').value * document.getElementById('f2').value; } </script> <input id='f2' type='text' onchange='update()'><input id='f1' type='text' onchange='update()'><input id='answer' type='text'> Thanks. Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/#findComment-634651 Share on other sites More sharing options...
discomatt Posted September 5, 2008 Share Posted September 5, 2008 Might as well just update the innerHTML of a span... that way there's no editing anyways Link to comment https://forums.phpfreaks.com/topic/122649-instantanious-form-field-multiplication/#findComment-634654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.