By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to link a checkbox to a textbox?

P: 10
Hello,

I am doing a search engine for a traditionnal music information centre. I would like that the user can enter the name of a musician in a textbox and then check the function of the musician (compositor, singer...) thanks to a checkbox. The database has fields "compositor", "singer" ... where the name of the musician has been entered.
I canīt find what kind of script I have to write to make it work.
Thanks for your help and sorry for my broken English!!
Jun 4 '07 #1
Share this Question
Share on Google+
4 Replies


pbmods
Expert 5K+
P: 5,821
Heya, Phaelle. Welcome to TSDN!

I would like that the user can enter the name of a musician in a textbox and then check the function of the musician (compositor, singer...) thanks to a checkbox. The database has fields "compositor", "singer" ... where the name of the musician has been entered.
In most (all?) browsers, a checkbox will send a value of 'ON' when checked, and it will not send any value if unchecked. In other words, if you had a form that contained a checkbox that looked like this:

Expand|Select|Wrap|Line Numbers
  1. <input name="cat[composer]" type="checkbox" /> Composer
  2.  
If it were checked and the User submitted your form, then the value of $_REQUEST['cat']['composer'] would be 'ON'. But if the checkbox were unchecked when the form was submitted, the value of $_REQUEST['cat']['composer'] would be null.
Jun 4 '07 #2

P: 40
I am pretty new at this PHP thing, but......

I tried writing a form with some checkbox fields, but I had errors when a checkbox was not checked. I ended up changing them to radio buttons configured to be "Yes/No' buttons. It may not be the best solution, but it worked. My code looked like this:
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td> Yes   No</td><td> Yes   No</td></tr>
  3. <tr>
  4. <td><input type="radio" name="assess_ortho" value="Y"> <input type="radio" name="assess_ortho" value="N" checked> Assess for orthostatic hypotension</td>
  5. <td><input type="radio" name="addr_bwlblddr" value="Y"> <input type="radio" name="addr_bwlblddr" value="N" checked> Address bowel/bladder needs</td>
  6. </tr>
  7.  
Hope that helps.

jej1216
Jun 4 '07 #3

ak1dnar
Expert 100+
P: 1,584
Hello,

I am doing a search engine for a traditionnal music information centre. I would like that the user can enter the name of a musician in a textbox and then check the function of the musician (compositor, singer...) thanks to a checkbox. The database has fields "compositor", "singer" ... where the name of the musician has been entered.
I canīt find what kind of script I have to write to make it work.
Thanks for your help and sorry for my broken English!!
Phaelle,
Just look at this example.If you have a table with this Structure.

Name : Mike Simpson
Role : Singer

Name : John Linkan
Role : musician


Using this type of form with check boxes, you can go for a search.
Please Note that i didn't add the textbox for enter the name of the person to this.

[HTML]<form action="search.php" method="post">
musician<input name="musician" type="checkbox" value="musician" />
compositor<input name="compositor" type="checkbox" value="compositor" />
singer<input name="singer" type="checkbox" value="singer" />
<input name="btn_search" type="submit" value="Search" />
</form>
[/HTML]

Here in the server side i am doing the coding like this.
search.php
[PHP]<?php
$string = array();
$where = "";

if (isset($_REQUEST['musician']) AND !empty($_REQUEST['musician']))
$string[] = " col_name = '".$_REQUEST['musician']."' ";
if (isset($_REQUEST['compositor']) AND !empty($_REQUEST['compositor']))
$string[] = " col_name = '".$_REQUEST['compositor']."' ";
if (isset($_REQUEST['singer']) AND !empty($_REQUEST['singer']))
$string[] = " col_name = '".$_REQUEST['singer']."' ";

if(!empty($string))
$where = " WHERE ".implode("OR", $string);
$sql="SELECT * FROM table_name $where GROUP BY col_id ORDER BY col_id asc";
echo $sql;

?>[/PHP]

Just run this sample and try to understand what i have done here.

NOTE:
This a open invitation to all you guys to do the changes to this script and make it smoother.
Jun 5 '07 #4

P: 10
Thanks for your help. It helps me a lot
Jun 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.