clonetrooper9494 Posted October 26, 2007 Share Posted October 26, 2007 I was making a JavaScript and it doesn't do what I want it to do. I want it to make the value of a text box the same as 2 other text boxes combined. But I am not sure how to... I am skimming through the sites tutorial, but that doesn't seem to help, its very confusing to me. If you know how to fix the problem, please tell me.The java script: <script LANGUAGE="JavaScript">function fusethem() {var 1 = form.1.valuevar 2 = form.2.valueif (1 = "test")form.3.value = ("1" + "2")</script> The Body: <center><form name=idform>1: <input type=text name=1 value=test><br>2: <input type=text name=2 value=ing><br>3: <input type=text name=3 onFocus="this.blur()"><br><input type="button" value="combine" onClick="java script:fusethem()" ></form></center> Link to comment Share on other sites More sharing options...
Reg Edit Posted October 26, 2007 Share Posted October 26, 2007 I was making a JavaScript and it doesn't do what I want it to do. I want it to make the value of a text box the same as 2 other text boxes combined. But I am not sure how to... I am skimming through the sites tutorial, but that doesn't seem to help, its very confusing to me. If you know how to fix the problem, please tell me.A few changes needed to make it work:Don't use a number as a javascript variable name (because a number already has a meaning as a number!) Don't put javascript variable names in quotes For cross-browser compatibility, use html element ids not names where possible Use "document.getElementById" to access html elements Don't include "java script:" in onclick event attributes (but when it is needed, in places like href attributes, it is one word "javascript", not two words) The updated lines of code: function fusethem() {var v1 = document.getElementById('1').value;var v2 = document.getElementById('2').value;document.getElementById('3').value = v1 + v2;}...1: <input type=text id="1" value=test><br>2: <input type=text id="2" value=ing><br>3: <input type=text id="3" onFocus="this.blur()"><br><input type="button" value="combine" onClick="fusethem()" > Link to comment Share on other sites More sharing options...
clonetrooper9494 Posted October 26, 2007 Author Share Posted October 26, 2007 Thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.