SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    i want to repost the input...

    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;
    thanks in advance

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,448
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    I think part of the problem is that the textfield is not disabled, but inside <noscript tags.

    Rather than by default not have it, and conditionally append one, maybe if you had it there and used code to disable/hide it unless the radio is checked it would work better?

    That is, if a user does not have javascript enabled, the textfield would show (as it does now in noscript), otherwise it would conditionally show depending on the radio.

  3. #3
    SitePoint Member
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my textfield is disabled as default, but when its radio button is checked it will enable.
    the problem is when i try to post the value of the text field it is still enable eventhough it has value already.


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
  •