Jump to content


Photo

Query To Determine A Checkbox Greyed Out


  • Please log in to reply
8 replies to this topic

#1 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 17 August 2006 - 06:13 PM

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:

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

Hopefully what I am asking for has made sense.

Thankyou kindly in advance :)

#2 appeland

appeland
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 17 August 2006 - 06:43 PM

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

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

Have fun !
aNDI

#3 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 17 August 2006 - 07:19 PM

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?

#4 HeyRay2

HeyRay2
  • Members
  • PipPipPip
  • Advanced Member
  • 223 posts

Posted 17 August 2006 - 07:22 PM

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


#5 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 17 August 2006 - 07:33 PM

^^ That looks very close !

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

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

#6 appeland

appeland
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 17 August 2006 - 08:46 PM

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

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

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

tata,
Andi


#7 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 17 August 2006 - 09:17 PM

Indeed it does make sense :)

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

So thankyou to you both.

Last step now, displaying a snipet of text next to the box saying "Function disabled"
Is that possible?

#8 appeland

appeland
  • Members
  • PipPipPip
  • Advanced Member
  • 30 posts

Posted 17 August 2006 - 09:21 PM

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

#9 NFD

NFD
  • Members
  • PipPipPip
  • Advanced Member
  • 44 posts

Posted 17 August 2006 - 09:38 PM

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 :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users