View Full Version : Modifying an item in an array of text boxes

09-26-2005, 02:32 PM
I have an array of textboxes that is created dynamically using PHP. The text boxes are called description[X] where X is an integer from 0. Also generated is an array of buttons called delete[X] where X is the same integer.

I basically need a function that, when delete[X] is pressed, changes the value of description[X] to a certain string ("DELETED", for example) so that I can play around with it in PHP.

Try as I might, and after frantic searching through my JavaScript in 24 hours book, I still can't work out how to do it. Please help!

09-27-2005, 01:41 PM
<script type="text/javascript">
function deleteDesc(index, oForm){
oForm.elements["description["+index+"]"].value = "DELETED";
<input type="button" name="delete[0]" value="Delete" onclick="deleteDesc(0, this.form)" />
<input type="button" name="delete[1]" value="Delete" onclick="deleteDesc(1, this.form)" />

<input type="text" name="description[0]" />
<input type="text" name="description[1]" />

See my sig for more info of square bracket notation.

09-27-2005, 03:44 PM
Works perfectly! Thanks a lot! :)