www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Dynamically add onclick event

  1. #1
    Join Date
    Feb 2010
    Posts
    2

    resolved [RESOLVED] Dynamically add onclick event

    Hi Everyone,
    Having problems with a function and hoping someone can help me out.

    I have a function that dynamically creates a new div,part of the function looks like:

    root = document.getElementById('rootbox2');
    var oDiv=root.appendChild(document.createElement("div"));
    with(oDiv){
    id=ji;
    className="workshopRow";
    setAttribute("attending","");
    setAttribute("attending_count","0");
    }
    var oText = oDiv.appendChild (document.createTextNode(""));
    var oDiv1=oDiv.appendChild(document.createElement("div"));
    with(oDiv1){
    className="workshopName";
    }
    var oText = oDiv1.appendChild (document.createTextNode(""));
    var oSelect=oDiv1.appendChild(document.createElement("select"));
    with(oSelect){
    name="select_"+ji;
    id="select_"+ji;
    className="workshop";
    onchange="calc_subtotal("+ji+")";
    }
    var oText = oSelect.appendChild (document.createTextNode(""));
    var oOption=oSelect.appendChild(document.createElement("option"));
    with(oOption){
    value="12";
    setAttribute("price",10);
    }

    what im looking to do is add an onchange event to the select element, not sure if i have programmed it correctly but it does not seem to work.

    any help would be greatly appreciated

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    oSelect.onchange=new Function("calc_subtotal("+ji+")");
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Feb 2010
    Posts
    2

    fantastic

    Thanks for your help Fang, works perfectly..

    Cheers

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