soona Posted November 6, 2008 Share Posted November 6, 2008 hi Experts,In javascript :-> how to change text box value automatically ? when will give text box value from another input box?I gave code below.pls check . where i made mistake.----------------------------------------The javascript code as follows:<script language="javascript" type="text/javascript">function Fn_Add(){var first ="0"var second="0"var third="0"if(document.getElementById ("TextBox1").value!=""){first =document.getElementById ("TextBox1").value}else{document.getElementById("TextBox1").value="0"}if(document.getElementById ("TextBox2").value!=""){second=document.getElementById ("TextBox2").value}else{document.getElementById("TextBox2").value="0"}if(document.getElementById ("TextBox3").value!=""){third=document.getElementById ("TextBox3").value}else{document.getElementById("TextBox3").value="0"}document.getElementById ("TextBox4").value=parseInt(first)+parseInt(second) + parseInt(third)}</script>------------------------------------------now i given Three(3) Textbox value add And Result display in TextBox4...suppouse you given TextBox1 & TextBox3 value(ex:100,200) but didn't given TextBox2 values in run time...TextBox2 value built in 0 automaticaly...At that time of running in webpage you make it to change Each & Every single digit value in any Textbox automaticaly change the Result value...With kind regardsNancy Link to comment Share on other sites More sharing options...
MinusMyThoughts Posted November 6, 2008 Share Posted November 6, 2008 You need to have a function that runs onchange. That way, when a value changes, the function is triggered and will recalculate the values. <script type="text/javascript">function recalc() { // code to check textbox 1 . . . // code to check textbox 2 . . . // code to check textbox 3 . . . // add them up, change the text document.getElementById("TextBox4").value = tb1+tb2+tb3;}</script><input id="TextBox4" type="text" value="" onChange="java script:recalc();" /> Something like that will at least get you headed in the right direction.-Jason Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.