PDA

View Full Version : radio button with text field



syntaxerror
05-09-2009, 07:59 AM
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:


<!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


<!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


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

forum_amnesiac
05-10-2009, 03:58 PM
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.

syntaxerror
05-11-2009, 01:52 AM
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

forum_amnesiac
05-11-2009, 08:13 AM
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.


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

syntaxerror
05-11-2009, 08:42 AM
hi,
in your 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?

forum_amnesiac
05-11-2009, 09:25 AM
I always get confused between "and" and "or", that's why I normally experiment with it.

Try this code :


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

syntaxerror
05-12-2009, 01:21 AM
help please.....