...

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



dunce
09-26-2005, 01: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!

glenngv
09-27-2005, 12:41 PM
<script type="text/javascript">
function deleteDesc(index, oForm){
oForm.elements["description["+index+"]"].value = "DELETED";
}
</script>
...
<form>
<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]" />
...
</form>

See my sig for more info of square bracket notation.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum