Jump to content

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

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.