Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
select all tick box????
Old 09-15-2007, 07:07 AM select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
hello,

i have seen on a whole ton of things where you get a list of stuff with a tick box next to each where you can go along.. tick the ones you want and submit and it could delete those ticked or whatever.

but how do you do the thing where theres one tick box which selects all the other tick boxes... how do i do that?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 09-15-2007, 09:12 AM Re: select all tick box????
Nathand's Avatar
Extreme Talker

Posts: 233
Location: USA
Trades: 0
You make a for loop that cycles through all the check box elements and changes there value/state to checked.

You can view the source here to see what I mean.

http://smartwebby.com/DHTML/check_clear_all.asp

-Nathan
Nathand is offline
Reply With Quote
View Public Profile
 
Old 09-15-2007, 09:44 AM Re: select all tick box????
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
with javascript
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-15-2007, 09:54 AM Re: select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
I thought it would probably be javascript after i posted, thanks for moving ChrisHirst.

just looked at that thing nathan do you have a easier to read example?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-15-2007, 11:34 AM Re: select all tick box????
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
It's a simple enough script Hopefully the explanation is clear enough.

<link type="self-promo">
Select All Checkboxes
</link>
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-15-2007, 03:17 PM Re: select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Hey thanks chrishirst thats much easier for me to get

one problem.. i done it and its only checking the first box

all my check boxes are being done with a while statment

basically this:

PHP Code:
echo '<td><input type="checkbox" name="chk" value="'.$img_id.'" /></td>'
in a while($new_images=mysql_fetch_array($new_query))


and this is what i have above the while

PHP Code:
echo '<form action="admin.php?do=all" name="approveform" id="approveform" method="post">';
echo 
'<input type="checkbox" name="chkall" onclick="chkAll(\'chk\',this.checked)"> Select all <br />'
and i have this:

Code:
// Select All checkboxes in form function
function chkAll(name, value) {
// hardcoded form name 
 var frm = document.getElementById('approveform');
// get all inputs from the form into an array
 var inputs = frm.getElementsByTagName('input');
// loop through the form inputs 
 for (var i=0; i<inputs.length;i++) {
//if the name matches, set the value to match the calling element
  if (inputs[i].name == name) {
   inputs[i].checked = value;
  }
 }
}
in a seperate file and have it included in my head...

whats wrong? o.0

please help

Thanks

dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-15-2007, 03:38 PM Re: select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
O wait could it be because i have a form within a form?

PHP Code:
$new_query mysql_query("SELECT * FROM images WHERE status='new'") or die("Error getitng new image from db");
echo 
'<form action="admin.php?do=all" name="approveform" id="approveform" method="post">';
echo 
'<input type="checkbox" name="chkall" onclick="chkAll(\'chk\',this.checked)"> Select all <br />';
echo 
'<table border="1">';
echo 
'<tr><td>select all</td> <td>Image</td> <td>Upload Date</td> <td>Approve/Remove</td></tr>';
while(
$new_images=mysql_fetch_array($new_query))
{
$img_id $new_images['id'];
$img_file $new_images['image_name'];
$img_status $new_images['status'];
$img_date $new_images['date_added'];
$img_ip $new_images['user_ip'];
echo 
"<tr>";
echo 
'<td><input type="checkbox" name="chk" value="'.$img_id.'" /></td>';
echo 
'<td><a href="upload/'.$img_file.'" title="'.$img_file.' Uploaded on: '.$img_date.'"  rel="lightbox[new]" >
<img src="upload/'
.$img_file.'" style="height:120px" /></a></td>';
echo 
'<td>'.$img_date.'</td>';
echo 
'<td>
<form action="admin2.php?do=approve&id='
.$img_id.'" method="post">
<input type="submit" name="approve" value="Approve" />
<input type="submit" name="remove" value="Remove" />
</form></td>'
;
}
echo 
'</table>';
echo 
'</form>'
here it is

how do i make it work please

okay it definatly the form within a form which is muffing it up (i commented it out and the tick thing works)

how can i do this?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE

Last edited by dansgalaxy; 09-15-2007 at 03:40 PM..
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-15-2007, 08:12 PM Re: select all tick box????
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I don't really see why you have nested forms, it will often cause problems.

It appears you are having a approve/remove button for every image (assuming I've read your code right)

Personally I would have a single form and handle the mutiple approve selections server side.

At a guess your SQL query would only need to be modified slightly

something like

UPDATE table SET approved = true WHERE imageID IN ($_POST["chk"]) ;

this method works because checkboxes only return a value when checked, and are sent as a comma seperated list, which fits in nicely with the SQL IN() function.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-16-2007, 09:27 AM Re: select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
I have ended up giving up now and have it so he has to approve each individually..

but...

Ok i think i get what you mean but if i was to have the buttons in like the form, how would i do it? because at the moment i have it so if the approve button is clicked it will go to do=approve&id=ID TO APPROVE so it just gets the id from it and it is done.

So how could i do this because i think i have ended up with some messy code
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-16-2007, 10:54 AM Re: select all tick box????
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
there would only be one submit button at the end of the form

My approach to something like this is to have seperate buttons at the end of or at the top of the form (or both) and then have server side logic to decide which was pressed.
So there is one button labeled "Accept" and one labeled "Delete", all are named submit.

in Pseudocode

if post['submit'] == "Accept"
run code to accept selected
end if
if post['submit'] == "Delete"
run code to delete selected
end if

If you need edit capabilities, say for user management, then another submit button could be added for "Edit", only this one would need to be disabled on multiple selections, And then
if post['submit'] == "Edit"
run code to edit the selected record
end if
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 09-16-2007, 11:14 AM Re: select all tick box????
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
but how would i do this when i have a list of all these bits throw a while() so how the hell would it know which accept goes to which image?...
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-16-2007, 11:38 AM Re: select all tick box????
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Your checkboxes carry the imageID when checked

so the return value for chk might be "1,2,3,4 6,27,890" for example.

with that, you could split it into individual numbers and loop through or just use the value in a IN operator.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to select all tick box????
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34906 seconds with 12 queries