am trying to link the two together that if you click no on the radio button, it will activate the text field
<form>
<input type="radio" name="oRad2" onClick="javascript:this.form.text2.disabled=true;" /> Yes<br />
<input type="radio" name="oRad2" onClick="javascript:this.form.text2.disabled=false;" />No.If No-Reason
<textarea name="text2" rows="5" cols="30"></textarea>
</form>
this seem to solve the problem but how do i code the name to be passed to the database?
Problems with radio buttons and text field
Problems with radio buttons and text field
Last edited by intern3t on 07 Nov 2012, 16:27, edited 1 time in total.
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
Narrow down your code to the area that's causing a problem. Nobody wants to read 100 lines of HTML to find your problem.
¯\_(ツ)_/¯ It works on my machine...
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
i have finally arrived at this:
THE PHP:
THE HTML
The problem is when i click on submit, it gives me
please i need help to resolve this.thanks
THE PHP:
Code: Select all
<?php require_once('Connections/nawfia_test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO testing (agree_yes, agree_no_reason) VALUES (%s, %s)",
GetSQLValueString($_POST['grp_two'], "text"),
GetSQLValueString($_POST['text_two'], "text"));
mysql_select_db($database_nawfia_test, $nawfia_test);
$Result1 = mysql_query($insertSQL, $nawfia_test) or die(mysql_error());
}
?>
THE HTML
Code: Select all
<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<input type="radio" name="grp_two" class="radclass cant" value="option_two" />
Yes
<br />
<br />
<input type="radio" name="grp_two" class="radclass can" value="option_other" />
No. Give Reason
<textarea name="text_two" class="textclass grp_two" rows="5" cols="30"></textarea>
<br />
<input type="submit" name="submit" value="submit">
<input type="hidden" name="MM_insert" value="form1" />
</form>
<script type="text/javascript">
$('.textclass').attr({disabled:true,enabled:false});
$('.radclass.can').click(function(){
var grp = $(this).attr('name');
$('.' + grp).attr({disabled:false,enabled:true});
});
$('.radclass.cant').click(function(){
var grp = $(this).attr('name');
$('.' + grp).attr({disabled:true,enabled:false});
});
</script>
Code: Select all
Notice: Undefined index: text_two in C:\xampp\htdocs\NAWFIA\test.php on line 42
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
Why are you disabling the textarea?
$('.textclass').attr({disabled:true,enabled:false});
"The best place to hide a tree, is in a forest"
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
cats wrote:Why are you disabling the textarea?
$('.textclass').attr({disabled:true,enabled:false});
Because i want it to be activated only when you want to give reasons.
if you select yes, it will be disabled, when you select no, the text area will be enabled for you to give reasons. Is there anything i should correct.please help.
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
Alright.
Well I haven't tried your code yet, but it looks to me like this wont work
The class of the textarea is
Or maybe I have missed something.
Is this all the code or have you made any changes since you posted it?
Well I haven't tried your code yet, but it looks to me like this wont work
The class of the textarea is
While you are selecting "grp" here.grp_two
Or maybe I have missed something.
Is this all the code or have you made any changes since you posted it?
$('.' + grp).attr({disabled:true,enabled:false});
"The best place to hide a tree, is in a forest"
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
cats wrote:Alright.
Well I haven't tried your code yet, but it looks to me like this wont work
The class of the textarea is
While you are selecting "grp" here.grp_two
Or maybe I have missed something.
Is this all the code or have you made any changes since you posted it?
$('.' + grp).attr({disabled:true,enabled:false});
i haven't made any changes.if you can recode mine, i will be glad.i just need the way forward or you can drop your suggestion.thanks
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
Now working!!!
i had to change this :
to
i used @ to suppress the notice.i guess it doesn't matter since its a notice, not an error.or does it?
i had to change this :
Code: Select all
$insertSQL = sprintf("INSERT INTO testing (agree_yes, agree_no_reason)
Code: Select all
@$insertSQL = sprintf("INSERT INTO testing (agree_yes, agree_no_reason)
Re: PROBLEM WITH RADIO BUTTONS AND TEXT FIELD
Well that depends ^^
If text_two is not defined then there might be another problem that makes it so that the data isn't submitted correctly.
But maybe that was the point from the beginning? That the textarea is disabled at some point and thus not submitted?
You might want to fix the error instead by checking if the data is submitted, and if not, insert a default value or something instead, as it might give you unwanted results later from the database.
If text_two is not defined then there might be another problem that makes it so that the data isn't submitted correctly.
But maybe that was the point from the beginning? That the textarea is disabled at some point and thus not submitted?
You might want to fix the error instead by checking if the data is submitted, and if not, insert a default value or something instead, as it might give you unwanted results later from the database.
"The best place to hide a tree, is in a forest"