dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Sending parameters to JS function from input text box generated at run time

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Question Sending parameters to JS function from input text box generated at run time

    Hi,
    I am trying to display a list of events, that are thrown from JSON, and displayed using JS dynamically using .APPEND
    I am also adding a textbox QTY for each event and ADD TO CART link, so people can enter the number of tickets they reserve for the event and add it to the cart.

    How do I send the parameters to the JS function about what's entered in the qty textbox, this is what I have:

    function initEvents(){
    for (i = 0; i < allevents.length; i++) {
    $('div#eventcontainer').append('<div id="rightcolumn"><h2>' + allevents[i].eventname + '</h2><br /><br />' + allevents[i].starttime + '<br /><br />' + allevents[i].endtime + '<br />qty: <input id="qty" type="text"><br /><a href="#" onclick="addToCart(\'' + allevents[i].id + '\',\'qty\')">add to cart</a></div>')
    }
    }

    addToCart function works great without 'qty', but when I add qty parameter it's not....

  2. #2
    Join Date
    Apr 2012
    Posts
    2
    figured it out

    function initEvents(){
    for (i = 0; i < allevents.length; i++) {
    $('div#eventcontainer').append('<div id="rightcolumn"><h2>' + allevents[i].eventname + '</h2><br /><br />' + allevents[i].starttime + '<br /><br />' + allevents[i].endtime + '<br />qty: <input type="text" name="qty" value="1"><br /><a href="#" onclick="addToCart(\'' + allevents[i].id + '\',qty['+ i +'].value)">add to cart</a></div>')
    }
    }

    function addToCart(id,qty){
    alert(id);
    alert(qty);

    }

Thread Information

Users Browsing this Thread

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

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