function AddTicket(eventid) { $.getJSON("/ajaxmini/gettickets/", { 'eventid': eventid }, function(e){ if (e.ok) { var tbl = document.getElementById('ticketTable'+eventid); var lastRow = tbl.rows.length; var iteration = lastRow+1; var row = tbl.insertRow(lastRow); var cellRight = row.insertCell(0); var el = document.createElement('select'); el.setAttribute('name', 'ticket'+ eventid + '-' + iteration); el.setAttribute('id', 'ticket'+ eventid + '-' + iteration); cellRight.appendChild(el); $('#ticket'+ eventid + '-' +iteration).append($(e.tickets)); var link = document.createElement('a'); link.setAttribute('href', '#'); link.setAttribute('name', 'ticket-link'+ eventid + '-' + iteration); link.setAttribute('id', 'ticket-link'+ eventid + '-' + iteration); link.setAttribute('class', 'ticketmix-delete'); link.setAttribute('onClick', "return RemoveTicket('"+ eventid + '-' + iteration +"');"); cellRight.appendChild(link); $('#ticket-link'+ eventid + '-' + iteration).append("x"); document.getElementById('ticket_number' + eventid).value = iteration; } else { //alert('bad'); } }); return false; } function RemoveTicket(eventid) { $("#ticket"+eventid).parent("td").remove(); return false; } function orderticket(eventid){ var ticket=[]; for(i=1;i<=$("#ticket_number"+ eventid).val();i++){ if ($("select[name='ticket"+ eventid + '-' +i+"'] option:selected").val() != undefined) { ticket.push($("select[name='ticket"+ eventid + '-' +i+"'] option:selected").val()); } } $.post("/ajaxmini/orderTicket/", { 'name': $("input[name='name"+ eventid +"']").val(), 'phone': $("input[name='phone"+ eventid +"']").val(), 'message': $("textarea[name='message"+ eventid +"']").val(), 'event_id':eventid, 'tickets': ticket }, function(e){ if (e.ok) { $("#tickerForm"+eventid).hide(); $("#sendOk"+eventid).show(); } else { //sender.html('Ошибка. Попробовать еще раз?'); } }, "json"); return false; }