www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Dynamically allocated select drop down menu item actions

Hybrid View

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    resolved [RESOLVED] Dynamically allocated select drop down menu item actions

    Hello there,
    I am somewhat new at javascript, and have found myself stuck and in need of help regarding dynamically allocated select drop down menu items. I have as of yet only been able to get a pop up alert when selecting anything from the select drop down menu [eg: alert('hello');] if not executing any logic-filter. My question is this: Can I access the fields from the select drop down directly by accessing it by name (eg: document.tokenform.sel.options....) as shown below in the function, or can I pass this via the myOnClick function? I would strongly appreciate any help that might be offered considering my encountered dilemma.
    Thanks, Jeff

    ....
    // select cell
    var cellRightSel = row.insertCell(1);
    var sel = document.createElement('select');
    sel.name = 'selRow' + lastRow + 3;
    sel.options[0] = new Option(x0, 'x0');
    sel.options[1] = new Option(x1, 'x1');
    sel.options[2] = new Option(x2, 'x2');
    cellRightSel.appendChild(sel);
    sel.onchange=myOnClick;
    }

    function myOnClick(e) {
    if(document.tokenform.sel.options[document.tokenform.sel.selectedIndex].value == "x1"){
    alert('Hello');
    }


    }

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    sel.onchange=function(){myOnClick(this.value);};
    
    function myOnClick(val) {
    if(val == "x1"){
    alert('Hello');
    }
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Thank you so much!

    Thank you Fang, you just made my day!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles