Jump to content

Query To Determine A Checkbox Greyed Out


NFD

Recommended Posts

Hi everyone,

Youve all been of great help to me in the pst, and Im hoping one of you can help me out with something.

What I want to do is have a query check a field of a table for data.
If data exists, then the checkbox is made available (ticked by default, can be changed)
If no data exists, then the box gets greyed out (unticked by default, obviously cant be changed)

In this example I am looking at a table called "customer" and the field is called "cellphone"

The tickbox will be part of a form, somethign like:

[code]    <td><input name="testing" class="textbox" type="checkbox" id="testing" value="1" /></td>[/code]

Hopefully what I am asking for has made sense.

Thankyou kindly in advance :)
Link to comment
Share on other sites

Hello,
not sure what you are looking for , to disable a checkbox
(any form field actually) add disabled to the tag
[code]<input name="testing" class="textbox" type="checkbox" id="testing" value="1" disabled />[/code]

Make the query just insert the disabled bit if there's no data.
[code] <input name="testing" class="textbox" type="checkbox" id="testing" value="1" <? if (!$queryresult){echo "disabled"; } ?> /> [/code]

Have fun !
aNDI
Link to comment
Share on other sites

Hi appeland, thankyou for your reply.

Ive just realised that the field in question is already being queried, so a slightly different approach is required.

Basically what I want is :
if $result[0]['cellphone']
returns an empty field
then for the tickbox to be set as disabled

Does that make sense?
Link to comment
Share on other sites

^^ That looks very close !

Currently it gives this error though:
[code]Parse error: syntax error, unexpected '{' in demo.php on line 379[/code]

Code looks like this:
[code]Line 379 <td><input name="cellphone" class="textbox" type="checkbox" id="cellphone" value="1" <?php if (empty($result['cellphone']){echo "disabled"; } ?> /> </td>[/code]
 
Link to comment
Share on other sites

we are getting the "FIMBLING FEELING" here (for everyone who has kids that makes sense :) )

[code]<input name="testing" class="textbox" type="checkbox" id="testing" value="1" <? if (!$result[0]['cellphone']) {echo "disabled"; } ?>/>[/code]

The "is empty" is represented by the "!" in front of the variable.

tata,
Andi
Link to comment
Share on other sites

Indeed it does make sense :)

I got it working using :
[code]<td><input name="cellphone" class="textbox" type="checkbox" id="cellphone" value="1" <? if (!$cellnumber){echo "disabled"; } ?> /> </td>[/code]

So thankyou to you both.

Last step now, displaying a snipet of text next to the box saying "Function disabled"
Is that possible?
Link to comment
Share on other sites

Hiho,
besides the fact that i would not do that (not working should be enough),
you can use the same code to do what ever else you want to display beside it :
<? if (!$cellnumber){echo "this will not work , regardless what you do dudeldidum, hihi"; } ?>
regards,
andi
Link to comment
Share on other sites

Hi Andi,

I figured that would work (and it does)
The message next to it was just a visual for that the customer does not have a cellnumber in the database
(an explaination for why it cant be ticked I guess)

All works, all is good.
Thankyou :)
Link to comment
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.