Jump to content

SetAttribute Onchange or onclick


flemingmike

Recommended Posts

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 by flemingmike
Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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);		
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.