Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Creating select box dynamically- onchange fired before selection

  1. #1
    Junior Member
    Join Date
    Dec 2010
    Posts
    7
    My Mood
    Stressed
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Creating select box dynamically- onchange fired before selection

    Hi,

    I need to create a select box on the click of a button using javascript. While creating the select box, I need to provide a function call for onchange event. The issue is that, the funtion gets invoked as soon as the select box gets added dynamically on button click. The source code on the rendered page has onchange="undefined".Below is my code:


    function addRowToTable(form, responseObj) {
    	if (responseObj.length <= 0) {
    		alert("Devices Not Available");
    		return;
    	} 
    		var tbl = document.getElementById('deviceTable');
    		var lastRow = tbl.rows.length;
    		// if there's no header row in the table, then iteration = lastRow + 1
    		var iteration = lastRow;
    		alert('iteration'+lastRow);
    		var row = tbl.insertRow(lastRow);
    		if (lastRow % 2 != 0) {
    			row.className = "oddrow";
    		} else {
    			row.className = "evenrow";
    		}
    		// left cell
    		var cellLeft = row.insertCell(0);
    		cellLeft.className = "rowtd";
    		var textNode = document.createTextNode(iteration);
    		cellLeft.appendChild(textNode);
     
    		var cellRightSel = row.insertCell(1);
    		cellRightSel.className = "rowtd";
    		var sel = document.createElement('select');
    		sel.name="deviceType"+lastRow;
    		sel.id="deviceType"+lastRow;
    		var selectId="deviceType"+lastRow;
     
    		for ( var x = 0; x < responseObj.length; x++) {
    			var twt = responseObj[x];
    			addOption1(sel, twt, twt, x);
    		}
    		sel.setAttribute("onchange", fetchUnMappedDeviceMake(selectId);});
     
    		cellRightSel.appendChild(sel);
     
    }


    Kindly help me to resolve this.


    Thanks in advance.

    Veronica


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Creating select box dynamically- onchange fired before selection

    Thread moved. This is a javascript question, so you might find more help on a javascript dedicated forum.

Similar Threads

  1. [SOLVED] Creating Dynamically Radio Buttons, Labels
    By Onur in forum Java Theory & Questions
    Replies: 15
    Last Post: August 25th, 2011, 08:39 AM
  2. Auto Select
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 14
    Last Post: May 31st, 2011, 04:55 AM
  3. Dynamically Creating User Selection through ResultSet
    By anmaston in forum Java Theory & Questions
    Replies: 3
    Last Post: April 10th, 2011, 11:08 AM
  4. onchange does not work
    By jai in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: March 9th, 2011, 04:10 AM