Forum Moderators: coopster

Message Too Old, No Replies

disabling a checkbox if challenges are present

         

nshack31

1:16 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



I have the code below. If a user is in the league the the checkbox is checked. But if the user is in the league and has challenges arranged then the checkbox is checked BUT the user cannot uncheck it (leave the league) because they have challenges


$queryleave = "SELECT confirmed FROM challenge WHERE clanid = '$id' OR themid = '$id' and leagueid = '1'";
$resultleave = mysql_query($queryleave);

$recordleave= mysql_fetch_assoc($resultleave);
$confirmed = $recordleave['confirmed'];

$queryleave2 = "SELECT confirmed FROM challenge WHERE clanid = '$id' OR themid = '$id' and leagueid = '2'";
$resultleave2 = mysql_query($queryleave2);

$recordleave2= mysql_fetch_assoc($resultleave2);
$confirmed2 = $recordleave2['confirmed'];

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$leagues[]=$row['leagueid'];
if(in_array(1,$leagues) && $confirmed == "")// if user is in ladder with no challenges
{
$box1 = 'checked'; // check box
}
else if (in_array(1,$leagues) && $confirmed!= "") // if user is in ladder with challenges
{
$box1 = 'checked DISABLED';// check box but its locked
$text1 = "cant leave as you have challenges!"; //say reason why box can't be unchecked
}
if(in_array(2,$leagues) && $confirmed2 == "")
{
$box2 = 'checked';
}
else if (in_array(2,$leagues) && $confirmed!= "") // if user is in ladder with challenges
{
$box2 = 'checked DISABLED';// check box but its locked
$text2 = "cant leave as you have challenges!"; //say reason why box can't be unchecked
}

My question is about the query part. Surely i dont need 2 queries here ($queryleave1 AND $queryleave2) . How can i shorted the code? thanks!

nshack31

2:04 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



think ive sorted it using anothre while loop and then

if(in_array(1,$leagues) &&!in_array(1,$leaguesleave))// if user is in ladder with no challenges

Thanks!

nshack31

2:47 pm on Mar 7, 2005 (gmt 0)

10+ Year Member



I have another question, I'll post it here as its similar to the code above.

If a the user is in league one and they have a match arranged then..

$box1 = 'checked DISABLED';

This is used..

<input type = \"checkbox\" name = \"ctf\" $box1>

it successfully prevents the user from unchecking the box if they have matches arranged.

BUT... If you hit submit, the code sends the box as UNCHECKED when it should be sending it as CHECKED, is this something to do with the disabled button? How can I prevent the user from unchecking the checked box and send the box as checked? thanks!

ergophobe

4:29 pm on Mar 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Well, you can't use readonly because (from the W3C HTML 4 Rec):

The following elements support the readonly attribute: INPUT and TEXTAREA.

And you can't use disabled because

Disabled controls cannot be successful.

Essentially, in W3C language, that means they can't get submitted by the form.

So, I think your best solution is this

<input type="checkbox" name="throw_me_away" disabled="disabled" checked="checked">
<input type="hidden" name="ctf" value="test">

That said, you are pulling the checked value from your DB. Why do you need it in your post array on the next page? I guess if that's the only thing you would be pulling from the DB, for the price on one post variable you save yourself then need of querying again.