PDA

View Full Version : Checkboxes?


LeoNeo
02-24-2006, 09:18 AM
Hi all

I'm creating a website at the mo, I'm not using CSS for layout as I'm still trying to grasp the concept of it (ie i'm still learning). So I'm using layers :oops:

Please view what i've done at the moment and take note of the check box's.

http://www.programmedia.co.uk/sport.html

What I need to know is how can I have a check box that say's all, so when you checkit it checks all the regions.

Any idea's?

ramandeep
02-24-2006, 09:22 AM
You can do this with javascript.
here is the tutorial for this
http://javascript.internet.com/buttons/check-all.html

LeoNeo
02-24-2006, 09:43 AM
Thanks but what I want is just a check box with all next it.

This script creates a button.

ramandeep
02-24-2006, 10:34 AM
Here you go

<HTML>
<HEAD>
<TITLE>Check all</TITLE>
<SCRIPT>
function checkBoxes (form, check) {
for (var c = 0; c < form.elements.length; c++)
if (form.elements[c].type == 'checkbox')
form.elements[c].checked = check;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
Check all
<INPUT TYPE="checkbox" NAME="checkAll"
ONCLICK="checkBoxes(this.form, this.checked)"
>


<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
</FORM>
</BODY>
</HTML>

domedia
02-24-2006, 01:15 PM
I'm not using CSS for layout as I'm still trying to grasp the concept of it (ie i'm still learning). So I'm using layers
uhm... If you use 'layers' in DW, you're using CSS. How else are the layers positioned?

LeoNeo
02-27-2006, 09:27 AM
I'm not using CSS for layout as I'm still trying to grasp the concept of it (ie i'm still learning). So I'm using layers
uhm... If you use 'layers' in DW, you're using CSS. How else are the layers positioned?

When you place the layer it creates the DIV tag, and sets it to absolute.

LeoNeo
02-27-2006, 09:33 AM
Here you go

<HTML>
<HEAD>
<TITLE>Check all</TITLE>
<SCRIPT>
function checkBoxes (form, check) {
for (var c = 0; c < form.elements.length; c++)
if (form.elements[c].type == 'checkbox')
form.elements[c].checked = check;
}
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="formName">
Check all
<INPUT TYPE="checkbox" NAME="checkAll"
ONCLICK="checkBoxes(this.form, this.checked)"
>


<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
<INPUT TYPE="checkbox">
</FORM>
</BODY>
</HTML>


When i put this code in where it tells me to it deletes the table that i've got in the layer for the form layout.

Is their anyway in dreamweaver that you can place a check box that checks the entire set of boxes :?:

See link above

domedia
02-27-2006, 01:43 PM
I'm not using CSS for layout as I'm still trying to grasp the concept of it (ie i'm still learning). So I'm using layers
uhm... If you use 'layers' in DW, you're using CSS. How else are the layers positioned?

When you place the layer it creates the DIV tag, and sets it to absolute.
That's CSS ;)

ramandeep
02-27-2006, 02:53 PM
Thats was a concept, you can modify it as per your page rather than copy pasting it.
Ok now to make it work on your page
Before your </script> tag in your code, add this

function checkBoxes (form, check) {
for (var c = 0; c < form.elements.length; c++)
if (form.elements[c].type == 'checkbox')
form.elements[c].checked = check;
}



and whereever you want to add the Check All check box , add this

<input type="checkbox" name="checkAll"
ONCLICK="checkBoxes(this.form, this.checked)"
> Check All


I tested it on your page and this works fine.

LeoNeo
02-28-2006, 02:36 PM
Thats was a concept, you can modify it as per your page rather than copy pasting it.
Ok now to make it work on your page
Before your </script> tag in your code, add this

function checkBoxes (form, check) {
for (var c = 0; c < form.elements.length; c++)
if (form.elements[c].type == 'checkbox')
form.elements[c].checked = check;
}



and whereever you want to add the Check All check box , add this

<input type="checkbox" name="checkAll"
ONCLICK="checkBoxes(this.form, this.checked)"
> Check All


I tested it on your page and this works fine.

Hi Ramandeep

I done what you told me to do and the check box goes in fine, but it won't check all the boxes, also the code sort of shows on the webpage behind the top header.

Would you like me to upload the page so you can see if I've done it right?

ramandeep
02-28-2006, 03:16 PM
Yes upload it!

LeoNeo
03-01-2006, 09:44 AM
Here's the link, also look at the top of the page just to the right.

http://www.programmedia.co.uk/music.html

Thanks Ram

ramandeep
03-01-2006, 10:14 AM
Mate you added the function at wrong place. All javascript funtions are to be placed in between <script> </script> tags.
Remove the function from current location and Add this right before your </script>

function checkBoxes (form, check) {
for (var c = 0; c < form.elements.length; c++)
if (form.elements[c].type == 'checkbox')
form.elements[c].checked = check;
}


Ok i have attached full page code just replace it or see how it is!

LeoNeo
03-01-2006, 11:08 AM
Excellent thanks Ram it works really appreciate that.

Another thing that is going wrong with the checkboxes, is they work fine in IE but in Firefox they mess up. What i mean by that is when you check london then central it deselects london then press yorkshire so and so.

If you can, can you view it Firefox to see what i mean, and would you know why its doin it.

I can't work it out.

Thanks

davidj
03-01-2006, 11:19 AM
ah the wonders of standardised browsers

my guess is that form.elements may not be standardised

you need to tear apart that function and check the compliance against different browsers

ramandeep
03-01-2006, 11:37 AM
Here comes our Javascript King (LOL), DJ i checked removing the this function but still have some problem in firefox.
I guess its not the funtion, must be something else!

LeoNeo
03-03-2006, 12:45 PM
Did davidj or ramandeep figure out how to sort out my checkbox problem?????

http://pages.infinit.net/bluefire/Images/nixweiss.gif