Jump to content

Aaaaaaaaaahhhhhhhhh! Help!


xProteuSx

Recommended Posts

I've got a PHP generated form which generates x amount of checkboxes, dependent on the number of values in an array.  Hence, if there are three items in an array, three checkboxes are generated in the following manner:

 

<form name="markform" method="post" action="somepage.html">

<input type="checkbox" name="marked[]" value="1" />

<input type="checkbox" name="marked[]" value="2" />

<input type="checkbox" name="marked[]" value="3" />

<img src="images/btn_check_all.png" onClick="checkAll()" /><br />  //check all boxes

<img src="images/btn_uncheck_all.png" onClick="uncheckAll()" /><br />  //uncheck all boxes

<input type="image" src="images/btn_update.png" />  //submit button

</form>

 

Now, if it wasn't for the fact that name="marked[]" is a javascript array, then my problem wouldn't be a problem.  I could just do this:

 

<SCRIPT LANGUAGE="JavaScript">

function checkAll()

{

var field = 'document.markform.marked';

for (i = 0; i < field.length; i++)

field.checked = true ;

}

 

function uncheckAll()

{

var field = 'document.markform.marked';

for (i = 0; i < field.length; i++)

field.checked = false ;

}

</script>

 

However, this does not seem to work:

 

var field = 'document.markform.marked[]';

 

How can I create 'Check All / Uncheck All' buttons when my input field name is an array??  Thanks.

 

 

Link to comment
https://forums.phpfreaks.com/topic/255408-aaaaaaaaaahhhhhhhhh-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.