Advanced Search

Results 1 to 7 of 7

Thread: radio button with text field

  1. #1
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default radio button with text field

    hi,
    can anyone please help me
    i have javasctipt,radio buttons, and textfield
    in default my textfield is disabled, and when any of radio buttons was click it is disabled also, but when the radio button of the textfield is click it will enable,
    it works fine and submit the correct data.
    when i went back to that page the radio button of the text field was checked ( ok its fine because it has value ) but it didnt show the value of the text field, and it is disabled.

    please kindly help

    here's my code
    index:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <!-- HOMER -->
    <script type="text/javascript">
    var textbox = function(me,field){
      if(me.checked == false){
        var textb = document.createElement('input');
        textb.type = "text";
        textb.name = field;
        me.parentNode.appendChild(textb);
      }
      setInterval(function(){
        if(me.checked == false){
           me.parentNode.removeChild(textb);
           return false;
        }
      }, 50);
    };  
    </script>
    <!-- HOMER -->
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    // some code
    mysql_select_db("samples", $con);
    $sql = "SELECT `subject` FROM topics order by id desc limit 1";
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
      {
      	$pref_info['Objection'] = $row[0];
      }
    echo $pref_info['Objection'];
    ?>
    <form name="pref_form" method="post" action="form4.php">
    							<TABLE width="700" cellpadding="2" cellspacing="2" border="0" bgcolor="#ffffff">
    <tr bgcolor="#e8e8e8">
    <TD WIDTH="36%" class="main">
    &nbsp;&nbsp;:Punctuation after “objection”
    </TD>
    <TD WIDTH="64%" class="main" valign="top">
    <input name="Objection" type="radio" value="3"<? print($pref_info['Objection'] == '3')? " checked" : ""; ?>> Objection.  Vague, asumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="2"<? print($pref_info['Objection'] == '2')? " checked" : ""; ?>> Objection.  Vague; asumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="1"<? print($pref_info['Objection'] == '1')? " checked" : ""; ?>> Objection.  Vague.  Assumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="0"<? print($pref_info['Objection'] == '0')? " checked" : ""; ?>> Objection; vague, assumes facts not in evidence.<br />
    <input type="radio" checked="checked" name="Objection" onmouseup="textbox(this,'Objection')"/>Other:<noscript><input name="Objection" width="250" type="text" value="<?php echo $pref_info['Objection']; ?>" /></noscript>
    </TD>
    </tr>
    <tr>
    <td width=36% align=right class="main">&nbsp;</td>
    <td><INPUT  type="submit" name="submit" value="Submit"></td>
    </tr>
    </TABLE>		
    </form>
    </body>
    </html>
    form2
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    <body>
    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    // some code
    mysql_select_db("samples", $con);
    $obj = $_POST['Objection'];
    $sql = "INSERT INTO topics (subject) values ('" . $obj ."')";
    $result = mysql_query($sql);
    if($result){
    echo "success";
    }else{
    echo "unsuccess";
    }
    echo $obj;
    ?>
    </body>
    </html>
    table
    Code:
    DROP TABLE IF EXISTS `samples`.`topics`;
    CREATE TABLE  `samples`.`topics` (
      `id` mediumint(9) NOT NULL auto_increment,
      `subject` varchar(60) NOT NULL default '',
      KEY `id` (`id`)
    ) ENGINE=MyISAM AUTO_INCREMENT=44 DEFAULT CHARSET=latin1;
    BTW its a PHP
    thanks in advance

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    When, and why, do you return to the input page, is it to re-display the input?

    Can you post a link to the page so that we can see what the problem is.

  3. #3
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    yes,
    i want to repost the input...
    my program is not online.
    but i provided here the 2 files and 1 table.
    just generate it

    thanks

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    I'm sorry I haven't the time to generate the database to test the code but here is some code that may lead you in the right direction.

    PHP Code:
    if (trim($pref_info['Objection']) != '' and print($pref_info['Objection'] != '1') and print($pref_info['Objection'] != '2') and print($pref_info['Objection'] != '3'))
    {
    $other = 1;
    }else{
    $other = 0;
    }

    ?>
    <form name="pref_form" method="post" action="form4.php">
                                <TABLE width="700" cellpadding="2" cellspacing="2" border="0" bgcolor="#ffffff">
    <tr bgcolor="#e8e8e8">
    <TD WIDTH="36%" class="main">
    &nbsp;&nbsp;:Punctuation after “objection”
    </TD>
    <TD WIDTH="64%" class="main" valign="top">
    <input name="Objection" type="radio" value="3"<? print($pref_info['Objection'] == '3')? " checked" ""?>> Objection.  Vague, asumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="2"<? print($pref_info['Objection'] == '2')? " checked" ""?>> Objection.  Vague; asumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="1"<? print($pref_info['Objection'] == '1')? " checked" ""?>> Objection.  Vague.  Assumes facts not in evidence.<br />
    <input name="Objection" type="radio" value="0"<? print($pref_info['Objection'] == '0')? " checked" ""?>> Objection; vague, assumes facts not in evidence.<br />
    <input type="radio" <? print($other == 1)? " checked" ""?><? if $other == 1){echo $pref_info['Objection'];} ?>
    I have tried to set the "other" box to checked if the value of the field is not null, 1, 2 or 3 and to then display the contents of the field.

    Give it a try, it can be formatted like a textbox later

  5. #5
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hi,
    in your code
    Code:
    if (trim($pref_info['Objection']) != '' and print($pref_info['Objection'] != '1') and print($pref_info['Objection'] != '2') and print($pref_info['Objection'] != '3'))
    i think instead of AND operator we should use || operator.
    what do you think?

  6. #6
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    I always get confused between "and" and "or", that's why I normally experiment with it.

    Try this code :

    PHP Code:
    $other=0;
    if (
    $Objection != ""){ 
        if (
    $Objection == "1" || $Objection == '2' || $Objection == '3'){
        
    $other=0;
        }else{
        
    $other 1
        }


  7. #7
    Join Date
    May 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    help please.....

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •