flemingmike Posted September 11, 2013 Share Posted September 11, 2013 (edited) hello, anyone able to help me with why the following may not be working? element6.setAttribute("onchange", "filllabour()"); here is my filllabour <script> //Calculate Labour function filllabour() { var txt6 = document.getElementsByName("lqLabour[]").value-0; var txt7 = document.getElementsByName("llabour[]").value-0; var txt8 = document.getElementsByName("lhelper[]").value-0; var markup = document.getElementsByName("lmarkup[]").value-0; var muresult = parseFloat(markup) / 100.0; document.getElementsByName("ltotal[]").value = ((txt6 * txt7) + (txt6 * txt8)) * (1 + muresult); } //Calculate Labour </script> here is my full insert column var column6 = row_in_table.insertCell(4); column6.setAttribute("align", "center"); var element6 = document.createElement("input"); element6.setAttribute("name", "lmarkup[]"); //to set name of the text box element6.setAttribute("id", "lmarkup"); element6.setAttribute("value", "30"); element6.setAttribute("size", "7"); element6.setAttribute("onchange", "filllabour()"); element6.type = "text"; column6.appendChild(element6); Edited September 11, 2013 by flemingmike Quote Link to comment Share on other sites More sharing options...
flemingmike Posted September 11, 2013 Author Share Posted September 11, 2013 here is something else im trying with no luck //to insert the sixth column (for textbox to accept age) var column5 = row_in_table.insertCell(5); column5.setAttribute("align", "center"); var element5 = document.createElement("input"); element5.setAttribute("name", "ltotal[]"); element5.setAttribute("id", "ltotal"); element5.setAttribute("value", ""); element5.setAttribute("size", "7"); element5.type = "text"; element5.onclick = function(filllabour) { alert("Changed!"); } column5.appendChild(element5); } // End Of Labour Table </script> <script> //Calculate Labour function filllabour() { var txt6 = document.getElementsByName("lqLabour[]").value-0; var txt7 = document.getElementsByName("llabour[]").value-0; var txt8 = document.getElementsByName("lhelper[]").value-0; var markup = document.getElementsByName("lmarkup[]").value-0; var muresult = parseFloat(markup) / 100.0; document.getElementsByName("ltotal[]").value = ((txt6 * txt7) + (txt6 * txt8)) * (1 + muresult); } //Calculate Labour </script> Quote Link to comment Share on other sites More sharing options...
nogray Posted September 11, 2013 Share Posted September 11, 2013 onclick or onchange are events and should be added either by addEventListener (and attachEvent for old IE browsers) or as the following element6.onchange = filllabour; // no parenthesis Quote Link to comment Share on other sites More sharing options...
flemingmike Posted September 12, 2013 Author Share Posted September 12, 2013 its not populating the total text box. here is the filllabour <script> //Calculate Labour function filllabour() { var txt6 = document.getElementsByName("lqlabour[]").value-0; var txt7 = document.getElementsByName("llabour[]").value-0; var txt8 = document.getElementsByName("lhelper[]").value-0; var markup = document.getElementsByName("lmarkup[]").value-0; var muresult = parseFloat(markup) / 100.0; document.getElementsByName("ltotal[]").value = ((txt6 * txt7) + (txt6 * txt8)) * (1 + muresult); } //Calculate Labour </script> here is my dynamic add //to insert the sixth column (for textbox to accept age) var column5 = row_in_table.insertCell(5); column5.setAttribute("align", "center"); var element5 = document.createElement("input"); element5.setAttribute("name", "ltotal[]"); element5.setAttribute("id", "ltotal"); element5.setAttribute("value", ""); element5.setAttribute("size", "7"); element5.type = "text"; element5.onchange = filllabour; column5.appendChild(element5); Quote Link to comment Share on other sites More sharing options...
nogray Posted September 12, 2013 Share Posted September 12, 2013 getElementsByName returns an HTML collections (or array) so you can't just assign a value to it. If you only have one element with that name, you can use document.getElementsByName("ltotal[]")[0].value = '.....'; // note the [0]; Otherwise use getElementById (each element needs a unique id). Quote Link to comment Share on other sites More sharing options...
priyankagound Posted September 18, 2013 Share Posted September 18, 2013 try document.getElementById document.getElementById("ctl00_ContentPlaceHolder1_txtCountry").setAttribute("onchange", "javascript:get_states(this);"); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.