Php unable to retrieve dynamic generated textfields - javascript

I was unable to retrieve the dynamic generated textfields and radio buttons that I created using javascript but was able to retrieve the those that I manually added into the form using html.
Previously, I use styling to hide and show all my textfields instead of dynamically created textfields, so I have no problem getting all the textfields and can safely assume my PHP processing doesn't have any problem.
My HTML/Interface coding
<?php
for ($x = 1; $x <= 5; $x++)
{
$inputAreaID = "inputArea".$x;// Creating all dynamic options and etc in this div using javascript
$typeID = "type".$x; //for select type id
$opt2ID = "ans".$x;
$optID = "opt".$x;
$comID = "com".$x;
$qnName = "qn".$x // for qn textfield name?>
<table>
<tr>
<td>Question <?php echo $x ?></td>
<td><input type="text" name='<?php echo $qnName ?>' required></td>
</tr>
<tr>
<td>Question Type</td>
<td>
<select id="<?php echo $typeID ?>" name="<?php echo $typeID ?>" onclick="showQuestionSelect('<?php echo $x ?>', '<?php echo $typeID ?>', '<?php echo $inputAreaID ?>')">
<option value="">Please select one option </option>
<option value="Yes,No">Yes/No </option>
<option value="True,False">True/False</option>
<option value="3">A. B. C. D.</option>
</select>
</td>
</tr>
</table>
<div id='<?php echo $inputAreaID ?>' style="margin-bottom: 1px;margin-top:1px;"></div>
JavaScript coding
function showQuestionSelect(questionNo, typeID, inputArea)
{
var s = String(typeID);
var i = String(inputArea);
var e = document.getElementById(s);
var selectedOpt = e.options[e.selectedIndex].value;
ansID = questionNo + "_ans";
comID = questionNo + "_com";
optA = questionNo + "_optA";
optB = questionNo + "_optB";
optC = questionNo + "_optC";
optD = questionNo + "_optD";
var msg = "";
if (selectedOpt == "True,False")
{
msg ="<div style='margin-bottom: 10px;margin-top:10px;'><input type='radio' name='"+ ansID + "' value='True'> Submit True as Answer<input type='radio' name='" +ansID +"' value='False'> Submit False as Answer</div>";
msg +="<div style='margin-bottom: 10px;margin-top:10px;'>Reason for the answer: <input type='text' name='" + comID + "' value='' /></div>"
}
else if (selectedOpt == 3)
{
msg = "<div style='margin-bottom: 10px;margin-top:10px;'>";
msg += "Option A: <input type='text' name='" + optA + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optA + "'> Submit as Answer <br><br>";
msg += "Option B: <input type='text' name='" + optB + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optB + "'> Submit as Answer <br><br>";
msg += "Option C: <input type='text' name='" + optC + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optC + "'> Submit as Answer <br><br>";
msg += "Option D: <input type='text' name='" + optD + "' value='' /> <input type='radio' name='" + ansID + "' value='" + optD + "'> Submit as Answer </div>";
msg +="<div style='margin-bottom: 10px;'>Reason for the answer: <input type='text' name='" + comID + "' value='' /></div>";
}
document.getElementById(i).innerHTML = msg;
}
PHP Processing Coding
for ($x = 1; $x <= 5; $x++)
{
$qn = $_POST["qn".$x]; // for qn textfield name
$type = $_POST["type".$x]; //for select type id
$ans = $_POST[$x."_ans"]; //for answer div id
$reason = $_POST[$x."_com"]; //for answer div id
$optionType = "";//to put into database
if ($type == "Yes,No")
{
$ans = "";
$reason = "";
}
if ($type == "3")
{
$optA = $_POST[$x."_optA"];
$optB = $_POST[$x."_optB"];
$optC = $_POST[$x."_optC"];
$optD = $_POST[$x."_optD"];
$optionType = $optA.",".$optB.",".$optC.",".$optD;
if ($ans == $x."_optA")
$ans = $optA;
else if ($ans == $x."_optB")
$ans = $optB;
else if ($ans == $x."_optC")
$ans = $optC;
else
$ans = $optD;
}
else
$optionType = $type;
Can anyone assist?

First of all you should to check server has got the values of those generated textfields. Try to display all members of $_POST[].
I guess that you are stuck in the names of the parameters

Related

I am trying to create a dynamic table. i want to get the number of rows equal to the number that user enters in the box

my problem is that i can not set an id for the input or a value. Because the input is inside JavaScript how can i call it ? and i want the values of the input change each time i enter a certain number.
i would like to see the values of the first column change, so if the user enter number four that means there are 4 lights.
function createTable() {
var a;
a = document.getElementById('number1').value;
if (a == 2 || a == 1 || a < 0) {
alert("Please enter a positive number greater than 2");
} else {
var rows = "<th>Light </th><th>Rating(W)</th><th>Span-from prev.light-(m)</th><th>Voltage Drop (v)</th><th>Voltage Drop( % ) </th>";
for (var i = 0; i < a; i++) {
rows += "<tr><td><input type='number' id=frt name='" + "Light".concat(i + 1) + "' id=li></td><td><input type='number' value=250 name='" + "Rating(W)".concat(i + 1) + "'><td><input type='number' value=40 name='" + "Span-from prev.light-(m)".concat(i + 1) + "'></td><td><input type='number' name='" + "Voltage Drop (v)".concat(i + 1) + "'></td><td id='amt'><input type='number' id='sum' onkeyup='myfunction(this.value);' name = '" + "Voltage Drop(%)".concat(i + 1) + "'> </td></tr >";
}
}
document.getElementById("table").innerHTML = rows;
}
<!DOCTYPE html>
<html>
<body>
<table cellpadding="1" cellspacing="1" border="1" id="table" style="font: 20px solid bold;font-weight: bold; background-color:#707B7C;color:black;"></table>
<input type="number" name="Numbers of Lights" id="number1" oninput="createTable()" value="3" style="width:40px; position: absolute;
top:300px; left:800px;">
</div>
</body>
</html>
If change the line to this
rows += "<tr><td><input value='" + (i + 1) + "' type='number' id=frt name='" + "Light".concat(i + 1) + "' id=li></td><td><input type='number' value=250 name='" + "Rating(W)".concat(i + 1) + "'><td><input type='number' value=40 name='" + "Span-from prev.light-(m)".concat(i + 1) + "'></td><td><input type='number' name='" + "Voltage Drop (v)".concat(i + 1) + "'></td><td id='amt'><input type='number' id='sum' onkeyup='myfunction(this.value);' name = '" + "Voltage Drop(%)".concat(i + 1) + "'> </td></tr >";
you can get the iteration as a value in the first column.

Cannot read property value of null. No value on onclick

I have a webpage that can update a table live with AJAX. I have some problems with the onlick function.
Whenever I click the update button it shows on console
Cannot read property 'value' of null(…)bb # manageaccounts.php:184 onclick # manageaccounts.php:229
I checked it in my update.php file but the code is just fine. I tried to change the onclick function from onclick="(this.id)" to onclick="(this.firstname)" but none worked.
manageaccounts.php
<body>
<div class="wrapper">
<div id="data" class="table"></div>
</div>
<script type="text/javascript">
data();
function data() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?status=disp", false);
xmlhttp.send(null);
document.getElementById("data").innerHTML = xmlhttp.responseText;
}
function aa(a) {
firstid = "firstname" + a;
txtfirstid = "txtfirst" + a;
var firstname = document.getElementById(firstid).innerHTML;
document.getElementById(firstid).innerHTML = "<input type='text' value='" + firstname + "' id='" + txtfirstid + "'>";
midid = "middlename" + a;
txtmidid = "txtmid" + a;
var middlename = document.getElementById(midid).innerHTML;
document.getElementById(midid).innerHTML = "<input type='text' value='" + middlename + "' id='" + txtmidid + "'>";
lastid = "lastname" + a;
txtlastid = "txtlast" + a;
var lastname = document.getElementById(lastid).innerHTML;
document.getElementById(lastid).innerHTML = "<input type='text' value='" + lastname + "' id='" + txtlastid + "'>";
addid = "address" + a;
txtaddid = "txtadd" + a;
var address = document.getElementById(addid).innerHTML;
document.getElementById(addid).innerHTML = "<input type='text' value='" + address + "' id='" + txtaddid + "'>";
gendid = "gender" + a;
txtgendid = "txtgend" + a;
var gender = document.getElementById(gendid).innerHTML;
document.getElementById(gendid).innerHTML = "<input type='text' value='" + gender + "' id='" + txtgendid + "'>";
contid = "contact" + a;
txtcontid = "txtcont" + a;
var contact = document.getElementById(contid).innerHTML;
document.getElementById(contid).innerHTML = "<input type='text' value='" + contact + "' id='" + txtcontid + "'>";
updateid = "update" + a;
document.getElementById(a).style.visibility = "hidden";
document.getElementById(updateid).style.visibility = "visible";
}
function bb(b) {
var firstid = "txtfirst" + b;
var firstname = document.getElementById(firstid).value;
var midid = "txtmid" + b;
var middlename = document.getElementById(midid).value;
var lastid = "txtlast" + b;
var lastname = document.getElementById(lastid).value;
var addid = "txtadd" + b;
var address = document.getElementById(addid).value;
var gendid = "txtgend" + b;
var gender = document.getElementById(gendid).value;
var contid = "txtcont" + b;
var contact = document.getElementById(contid).value;
update_value(b, firstname, middlename, lastname, address, gender, contact);
document.getElementById(b).style.visibility = "visible";
document.getElementById("update" + b).style.visibility = "hidden";
document.getElementById("firstname" + b).innerHTML = firstname;
document.getElementById("middlename" + b).innerHTML = middlename;
document.getElementById("lastname" + b).innerHTML = lastname;
document.getElementById("address" + b).innerHTML = address;
document.getElementById("gender" + b).innerHTML = gender;
document.getElementById("contact" + b).innerHTML = contact;
}
function update_value(id, firstname, middlename, lastname, address, gender, contact) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?id=" + id + " & firstname=" + firstname + " & middlename=" + middlename + " & lastname=" + lastname + " &address=" + address + " & gender=" + gender + " &contact=" + contact + " & status=update", false);
xmlhttp.send(null);
}
function delete1(id) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "update.php?id=" + id + " & status=delete", false);
xmlhttp.send(null);
data();
}
</script>
</body>
update.php has the null value onclick <input type="button" id="update<?php echo $row["id"]; ?>" name="<?php echo $row["id"]; ?>" value="UPDATE" style="visibility: hidden;" onclick="bb(this.firstname)">
<?php
$conn = mysqli_connect('localhost', 'root','root', 'realestate');
if (!$conn) {
die("Sorry we're having some problems with the database. :(".mysqli_connect_error());
}
$status = $_GET["status"];
if ($status == "disp") {
$sql1 = "SELECT * FROM agents"; // check the change ere
$result=mysqli_query($conn, $sql1);
echo "<table>";
echo "<tr>
<th>Agent ID</th>
<th>Firstname</th>
<th>Middlename</th>
<th>Lastname</th>
<th>Address</th>
<th>Gender</th>
<th>Contact</th>
<th>Action</th>
</tr>";
while($row=mysqli_fetch_assoc($result)) {
echo "<tr class='da'>";
echo "<td>"; echo $row["id"]; echo "</td>";
echo "<td>"; ?><div id="firstname<?php echo $row["id"]; ?>"><?php echo $row["firstname"]; ?></div><?php echo "</td>";
echo "<td>"; ?><div id="middlename<?php echo $row["id"]; ?>"><?php echo $row["middlename"]; ?></div><?php echo "</td>";
echo "<td>"; ?><div id="lastname<?php echo $row["id"]; ?>"><?php echo $row["lastname"]; ?></div><?php echo "</td>";
echo "<td>"; ?><div id="address<?php echo $row["id"]; ?>"><?php echo $row["address"]; ?></div><?php echo "</td>";
echo "<td>"; ?><div id="gender<?php echo $row["id"]; ?>"><?php echo $row["gender"]; ?></div><?php echo "</td>";
echo "<td>"; ?><div id="contact<?php echo $row["id"]; ?>"><?php echo $row["contact"]; ?></div><?php echo "</td>";
echo "<td>"; ?><button id="<?php echo $row["id"]; ?>" name="<?php echo $row["id"]; ?>" onclick="delete1(this.id)">DELETE</button><?php echo "</td>";
echo "<td>"; ?>
<input type="button" id="<?php echo $row["id"]; ?>" name="<?php echo $row["id"]; ?>" value="EDIT" onclick="aa(this.id)">
<input type="button" id="update<?php echo $row["id"]; ?>" name="<?php echo $row["id"]; ?>" value="UPDATE" style="visibility: hidden;" onclick="bb(this.firstname)">
<?php echo "</td>";
echo "</tr>";
}
echo "</table>";
}
if ($status == "update") {
$id = $_GET["id"];
$first = $_GET["firstname"];
$mid = $_GET["middlename"];
$last = $_GET["lastname"];
$add = $_GET["address"];
$gend = $_GET["gender"];
$cont = $_GET["contact"];
$first = trim($first);
$mid = trim($mid);
$last = trim($last);
$add = trim($add);
$gend = trim($gend);
$cont = trim($cont);
$sql2 = "UPDATE agents SET firstname='$first', middlename='$mid', lastname='$last', address='$add', gender='$gend', contact='$cont' WHERE id=$id";
$result = mysqli_query($conn, $sql2);
}
if ($status == "delete") {
$id = $_GET["id"];
$sql3 = "DELETE FROM agents WHERE id=$id";
$result = mysqli_query($conn, $sql3);
}
?>
In your function bb, you are doing:
var firstid="txtfirst"+b;
var firstname = document.getElementById(firstid).value;
You are calling the function like:
onclick="bb(this.firstname)"
Now, this.firstname would be undefined as this is pointing to your button and the button does not have a property called firstname.
Also, when you do like
onclick="(this.id)"
Then inside your function, firstid would become "txtfirstupdate1" as the id of your button will be update + id and not just id. So, document.getElementById(firstid) would be actually null and that's the reason why you are getting this error.

Dynamically creating a form

On my page, I show a table of entries. At the end of the table is a "modify" button. When the button is clicked the row turns into a form for directly modifying the contents.
This code:
element.innerHTML = "<tr class='alt_col'>";
element.innerHTML += "<form action='/RIDT/includes/modify_codeplug.inc.php' method='POST' name='modify_form'>";
element.innerHTML += "<td><input type='text' name='fileName' value='" + fileName + "'></td>";
element.innerHTML += "<td><input type='text' name='location' value='" + loc + "'></td>";
element.innerHTML += "<td><input type='text' name='build' value='" + build + "'></td>";
element.innerHTML += "<td><input type='text' name='version' value='" + version + "'></td>";
element.innerHTML += "<td><select name='type' id ='selectType'>" + descOptions + "</select></td>";
element.innerHTML += "<td><input type='hidden' name='id' value='" + id + "'/><input type='submit' value='Submit'/></td>";
element.innerHTML += "</form>";
element.innerHTML += "</tr>";
var options = document.getElementById("selectType").options;
for (i = 0; i < options.length; i++)
{
if (options[i].text == desc)
{
options[i].selected=true;
}
}
Results in the form being created like this:
<form action="/RIDT/includes/modify_codeplug.inc.php" method="POST" name="modify_form"></form>
With all of the forms input elements coming after the closing element. Why is the form being closed early?
Thanks for the help everyone. I will research all the suggestions provided more deeply later. In the interest of saving time I did it a different way. Instead of submitting a form, the submit button calls another javascript function that picks out the input data from the DOM, then builds and submits a hidden form to my php script. It's not pretty, but it got the job done.
I didn't test this, but jQuery has the same problem if you try to insert an unclosed element into the DOM. The closing tag is added for you.
Try this instead:
//track the html as a single string var
var html = "<tr class='alt_col'>";
html += "<form action='/RIDT/includes/modify_codeplug.inc.php' method='POST' name='modify_form'>";
html += "<td><input type='text' name='fileName' value='" + fileName + "'></td>";
html += "<td><input type='text' name='location' value='" + loc + "'></td>";
html += "<td><input type='text' name='build' value='" + build + "'></td>";
html += "<td><input type='text' name='version' value='" + version + "'></td>";
html += "<td><select name='type' id ='selectType'>" + descOptions + "</select></td>";
html += "<td><input type='hidden' name='id' value='" + id + "'/><input type='submit' value='Submit'/></td>";
html += "</form>";
html += "</tr>";
// set the html string once
element.innerHTML = html;

Javascript array contain value

<div id="image_div">
<input type="checkbox" />
<img src="1.jpg" />
<input type="checkbox" />
<img src="2.jpg" />
<input type="checkbox" />
<img src="3.jpg" />
<input type="checkbox" />
</div>
On page load, I return a JSON array:
{
"src":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","TDE2pWgIfa.jpg","tUtuDx1BEf.jpg"],
"checked":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","tUtuDx1BEf.jpg"]
}
The src contains all the source names of image and checked is the checked type of check boxes.
The checked defines which image is checked (every image has a check box).
I need the final HTML like this:
<div id="image_div">
<input type="checkbox" />
<img src="lml7x8nJzI.jpg" />
<input type="checkbox" checked /> //this is a checked one
<img src="TaR7dALIPJ.jpg" />
<input type="checkbox" checked/> //this is a checked one
<img src="TDE2pWgIfa.jpg" />
<input type="checkbox" /> //this is not
<img src="tUtuDx1BEf.jpg" />
<input type="checkbox" checked /> //this is a checked one
</div>
I can use array contains in JavaScript, or is there a better way?
My attempt:
var initial = "<ul class='gallary'>";
var middle = "";
var end = "</ul>";
var i;
for (i = 0; i < data.src.length; i++)
{
if (data.checked.contains(data.src[i])) // How can I do this?
{
middle = middle +
"<li><img src=" +
"http://localhost/project/user/" +
"<?php echo $this->session->userdata('username');?>" +
"/pages/" +
"<?php echo $this->uri->segment(3);?>" +
"/images/gallery/" +
data.src[i] +
" />" +
"<br /><input type='checkbox' value=" +
data.src[i] +
" checked/></li>";
}
else
{
middle = middle +
"<li><img src=" +
"http://localhost/project/user/" +
"<?php echo $this->session->userdata('username');?>" +
"/pages/" +
"<?php echo $this->uri->segment(3);?>" +
"/images/gallery/" +
data.src[i] +
" />" +
"<br /><input type='checkbox' value=" +
data.src[i] +
" /></li>";
}
}
var complete = initial + middle + end;
$("#project_gallary_layout").html(complete);
You can use indexOf method of Array
var a = ['a', 'b', 'c'];
if (a.indexOf('a') > -1 ) {
//element is in array
} else {
//element is not in array
}
Note that indexOf method is absent in IE6, but there is an implementation available by Mozilla on the same page.
Here's my complete solution using indexOf
$(function(){
var url = 'http://localhost/project/user/<?php echo $this->session->userdata('username'); ?>/pages/<?php echo $this->uri->segment(3); ?>/images/gallery/'
, complete = '<ul class="gallery">'
data.src.forEach(function(src){
complete += '<li><img src="' + url + src + '"><input type="checkbox" value="' + src + '"'
if(data.checked.indexOf(src) > -1){
complete += ' checked'
}
complete += '></li>'
})
$("#project_gallary_layout").html(complete);
})
A better approach would be to replace
{"src":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","TDE2pWgIfa.jpg","tUtuDx1BEf.jpg"],
"checked":["lml7x8nJzI.jpg","TaR7dALIPJ.jpg","tUtuDx1BEf.jpg"]}
with
{"src":[
{"src": "lml7x8nJzI.jpg", "checked": true},
{"src": "TaR7dALIPJ.jpg", "checked": true},
{"src": "TDE2pWgIfa.jpg", "checked": false},
{"src": "tUtuDx1BEf.jpg", "checked": true}]
}
for instance.
Then you could just write
for(i=0;i<data.src.length;i++) {
var elem = data.src[i];
var checked = "";
if (elem.checked)
checked = "checked";
middle = middle +
"<li><img src=" +
"http://localhost/project/user/" +
"<?php echo $this->session->userdata('username');?>" +
"/pages/" +
"<?php echo $this->uri->segment(3);?>" +
"/images/gallery/" +
elem.src +
" />" +
"<br /><input type='checkbox' value=" +
elem.src +
" " +
checked +
"/></li>";
}
}
The only thing different between the two strings you make is the attribute checked (which should really be checked="checked" if you want to follow standards), so I'd prefer setting a variable checked to either an empty string or "checked" depending on whether the checkbox is checked or not.

why this javascript function is not executing, no error in console

This function is a problem:
function addInvoiceItemValue(name,pkwiu,netto,unit,qty,vat) {
if(vat == '23') v23 = " selected='selected'";
if(vat == '22') v22 = " selected='selected'";
if(vat == '8') v8 = " selected='selected'";
if(vat == '7') v7 = " selected='selected'";
if(vat == '5') v5 = " selected='selected'";
if(vat == '3') v3 = " selected='selected'";
if(vat == '0') v0 = " selected='selected'";
if(vat == 'zw') vzw = " selected='selected'";
var vatSelect = "<option value='23'"+v23+">23%</option><option value='22'"+v22+">22%</option><option value='8'"+v8+">8%</option><option value='7'"+v7+">7%</option><option value='5'"+v5+">5%</option><option value='3'"+v3+">3%</option><option value='0'"+v0+">0%</option><option value='zw'"+vzw+">zw.</option>";
var row = "<tr id='item" + itemID + "'><td><input size='30' maxlength='300' id='ii-name-" + itemID + "' name='ii-name-" + itemID + "' value='" + name + "'></td>";
row += "<td><input size='6' maxlength='50' id='ii-pkwiu-" + itemID + "' name='ii-pkwiu-" + itemID + "' value='"+pkwiu+"'></td>";
row += "<td><input size='6' maxlength='16' id='ii-netto-" + itemID + "' name='ii-netto-" + itemID + "' value='"+netto+"'></td>";
row += "<td><input size='5' maxlength='128' id='ii-unit-" + itemID + "' name='ii-unit-" + itemID + "' value='"+unit+"'></td>";
row += "<td><input size='5' maxlength='6' id='ii-qty-" + itemID + "' name='ii-qty-" + itemID + "' value='"+qty+"'></td>";
row += "<td><select id='ii-vat-" + itemID + "' name='ii-vat-" + itemID + "'>" + vatSelect + "</select></td>";
row += "<td><a onclick='delInvoiceItem(\"item" + itemID + "\")'><b>-</b> Usuń</a></td></tr>";
$('#invoiceItems tr:last').after(row);
itemID++;
}
Example execution:
addInvoiceItemValue('yyy','','676.76','','1','23');
addInvoiceItemValue('fgh','','777.00','','1','8');
And here is function that work's fine:
function addInvoiceItem() {
var vatSelect = "<option value='23'>23%</option><option value='22'>22%</option><option value='8'>8%</option><option value='7'>7%</option><option value='5'>5%</option><option value='3'>3%</option><option value='0'>0%</option><option value='zw'>zw.</option>";
var row = "<tr id='item" + itemID + "'><td><input size='30' maxlength='300' id='ii-name-" + itemID + "' name='ii-name-" + itemID + "' value=''></td>";
row += "<td><input size='6' maxlength='50' id='ii-pkwiu-" + itemID + "' name='ii-pkwiu-" + itemID + "' value=''></td>";
row += "<td><input size='6' maxlength='16' id='ii-netto-" + itemID + "' name='ii-netto-" + itemID + "' value='0'></td>";
row += "<td><input size='5' maxlength='128' id='ii-unit-" + itemID + "' name='ii-unit-" + itemID + "' value=''></td>";
row += "<td><input size='5' maxlength='6' id='ii-qty-" + itemID + "' name='ii-qty-" + itemID + "' value='1'></td>";
row += "<td><select id='ii-vat-" + itemID + "' name='ii-vat-" + itemID + "'>" + vatSelect + "</select></td>";
row += "<td><a onclick='delInvoiceItem(\"item" + itemID + "\")'><b>-</b> Usuń</a></td></tr>";
$('#invoiceItems tr:last').after(row);
itemID++;
}
The v23, v22, v8, v7, v5, v3, v0, vzw and itemdID are not always defined in all code paths.
This causes the script to fail.
You should change your function to
function addInvoiceItemValue(name,pkwiu,netto,unit,qty,vat) {
var vats = ['23','22','8','7','5','3','0','zw'];
var vatSelect = '';
for (var i = 0; i < vats.length; i++)
{
vatSelect += '<option value="'+vats[i]+'"';
if (vat == vats[i])
vatSelect += ' selected="selected"';
vatSelect += '>'+vats[i] + '%</option>';
}
var row = "<tr id='item" + itemID + "'><td><input size='30' maxlength='300' id='ii-name-" + itemID + "' name='ii-name-" + itemID + "' value='" + name + "'></td>";
row += "<td><input size='6' maxlength='50' id='ii-pkwiu-" + itemID + "' name='ii-pkwiu-" + itemID + "' value='"+pkwiu+"'></td>";
row += "<td><input size='6' maxlength='16' id='ii-netto-" + itemID + "' name='ii-netto-" + itemID + "' value='"+netto+"'></td>";
row += "<td><input size='5' maxlength='128' id='ii-unit-" + itemID + "' name='ii-unit-" + itemID + "' value='"+unit+"'></td>";
row += "<td><input size='5' maxlength='6' id='ii-qty-" + itemID + "' name='ii-qty-" + itemID + "' value='"+qty+"'></td>";
row += "<td><select id='ii-vat-" + itemID + "' name='ii-vat-" + itemID + "'>" + vatSelect + "</select></td>";
row += "<td><a onclick='delInvoiceItem(\"item" + itemID + "\")'><b>-</b> Usuń</a></td></tr>";
$('#invoiceItems tr:last').after(row);
itemID++;
}
but the itemID also has to be defined.
When is it SUPPOSED to be executing?
While this technically bad coding practice, test with this:
<a href='#' onClick="javascript: function('value');" > Click Me </a>
If you click, and it still doesn't work, it is an issue with your function. If you click and it works, the function is never being called in the first place.
You should also check your selector.
$('#invoiceItems tr:last').after(row);
Try adding it in a simpler place. Make another div,...
Then use the selector $('#result');
In any case, if your selector is bad, it will never execute and it won't throw an error b/c it never had cause to do what you told it. Now that I think about it, I think this is the issue.
Do me a favor and try
$('#invoiceItems tr:last').each(alert('exist???'));
If it doesn't alert, your selector is most likely not working. (For each thing that meets the criteria , do an alert)

Categories