Jump to content

What am I missing?


derrickc

Recommended Posts

I have had this piece of code working a few hours ago, I tried tweaking it a bit and thought that I changed it back, but it still isnt working properly.  Very simple fix, I feel it is right in front of me but cant seem to see it.  Very simple, I'm adding dynamic text boxes and processing the the textboxes into an array.  To preface what I have done to warrent this outcome below is added 3 dynamic boxes to the already existing text box.  Box1.text = d, 2=6, 3=d, 4=d.  The outcome here is just my trouble to see where the problem is and I cant seem to find it.  please helps.  Thanks in advance.

 

This is the output:

0d

 

Notice: Undefined offset: 1 in C:\Program Files (x86)\PHP\www\last.php on line 11

1

2r

3d

 

<script>

function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);

// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.type = 'text';
el.name = 'txtRow[' + iteration + ']';
el.id = 'txtRow[' + iteration + ']';
el.size = 40;
cellRight.appendChild(el);
}

function removeRowFromTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2) tbl.deleteRow(lastRow - 1);
}


</script>
<BODY>
<form action="last.php" method="post">

<p>

<input type="button" value="Add" onclick="addRowToTable();" />

<input type="button" value="Remove" onclick="removeRowFromTable();" />

<input type="submit" value="save">

<input type="checkbox" id="chkValidate" onclick="validateRow(this.form);"/> Validate Submit

</p>

<p>

<input type="checkbox" id="chkValidateOnKeyPress" checked="checked" /> Display OnKeyPress

<span id="spanOutput" style="border: 1px solid #000; padding: 3px;"> </span>

</p>

<table border="1" id="tblSample">

<tr>

<th colspan="3">Sample table</th>

</tr>

<tr>

<td>1</td>

<td><input type="text" name="txtRow[]" id="txtRow[]" size="40" /></td>

</tr>

</table>

</form>

 

last.php looks like this:

	for($i = 0; $i < count($_POST['txtRow']); $i++){
             $textboxarr = $_POST['txtRow'][$i];
echo $i . $textboxarr .  "<br/>";;
    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.