How to link a checkbox to a textbox?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Phaelle
    New Member
    • Jun 2007
    • 10

    How to link a checkbox to a textbox?

    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!!
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Phaelle. Welcome to TSDN!

    Originally posted by Phaelle
    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:

    [code=html]
    <input name="cat[composer]" type="checkbox" /> Composer
    [/code]

    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.

    Comment

    • jej1216
      New Member
      • Aug 2006
      • 40

      #3
      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:
      [code=html]
      <tr>
      <td> Yes No</td><td> Yes No</td></tr>
      <tr>
      <td><input type="radio" name="assess_or tho" value="Y"> <input type="radio" name="assess_or tho" value="N" checked> Assess for orthostatic hypotension</td>
      <td><input type="radio" name="addr_bwlb lddr" value="Y"> <input type="radio" name="addr_bwlb lddr" value="N" checked> Address bowel/bladder needs</td>
      </tr>
      [/code]

      Hope that helps.

      jej1216

      Comment

      • ak1dnar
        Recognized Expert Top Contributor
        • Jan 2007
        • 1584

        #4
        Originally posted by Phaelle
        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<inpu t name="composito r" type="checkbox" value="composit or" />
        singer<input name="singer" type="checkbox" value="singer" />
        <input name="btn_searc h" 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($_REQUES T['musician']) AND !empty($_REQUES T['musician']))
        $string[] = " col_name = '".$_REQUEST['musician']."' ";
        if (isset($_REQUES T['compositor']) AND !empty($_REQUES T['compositor']))
        $string[] = " col_name = '".$_REQUEST['compositor']."' ";
        if (isset($_REQUES T['singer']) AND !empty($_REQUES T['singer']))
        $string[] = " col_name = '".$_REQUEST['singer']."' ";

        if(!empty($stri ng))
        $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.

        Comment

        • Phaelle
          New Member
          • Jun 2007
          • 10

          #5
          Thanks for your help. It helps me a lot

          Comment

          Working...