I am trying to make a small form that lets the user pick one element from 3 different radiobutton lists to set one element as the users active element (that will be stored to MySQL). Somehow along the way it does not work and I can not seem to figure out why, perhaps someone of you can see what I did wrong?
HTML:
<form name="activeForm1" method="post">
<fieldset data-role="controlgroup">
<div class="ui-radio">
<input type="radio" name="active" value="1" id="1">
<label for="1"></label></input>
</div>
<div class="ui-radio">
<input type="radio" name="active" value="2" id="2">
<label for="2"></label></input>
</div>
<div class="ui-radio">
<input type="radio" name="active" value="3" id="3">
<label for="3"></label></input>
</div>
</fieldset>
<div data-role="footer">
<input type="submit" href="#" onclick="setActive(1)"/>
</div>
</form>
JavaScript / Ajax call
function setActive(formid)
{
$.ajax(
{
type:'POST',
url:'active.php',
data:$('#activeForm'+formid).serialize(),
success:function(response)
{
}
}
);
}
PHP code:
session_start();
include('connectToDb.php');
$id = $_SESSION['id'];
if (isset($_POST['active']))
{
$formValue = $_POST['active'];
mail('my#mail.com','Test',$formValue,'From: dummy#mail.com');
mysql_query(/* UPDATE MySQL */);
header("Location: main.php");
}
else
{
mail('my#mail.com','Test','No data recieved!','From: dummy#mail.com');
}
So it works up until the if (isset($_POST['active'])) but then mails me that no data was recieved. I already have 2 similar forms on the same page and they are way bigger and has no problems running. Can't figure out what I did wrong here.
Wrong code :
data:$('#activeForm'+formid).serialize(),
#activeForm is not an id, it is the name of the form tag,
Correct the form tag to,
<form name="activeForm1" id="activeForm1" method="post">
Replace following line
data:$('#activeForm'+formid).serialize(),
with
data: $('form[name="activeForm'+formid+'"]').serialize(),
change
<input type="submit" href="#" onclick="setActive(1)"/>
to
<input type="button" href="#" onclick="setActive(1)"/>
and then it should work
Related
I am still working on my school project, which is almost finished.
With your help, I successfully created a working system that allows users to write, edit and delete data to/from the database.
The only problem I have right now us "user-friendly form." I managed to create auto-focus, insert correct values on edit so the user can see what was previously written in that field, etc.
I have my forms hidden with jquery. When a user clicks add, the form slides in. What I need to achieve is: "when a user clicks submit and the page refreshes and adds the element to the database, the form should appear again so users can add data faster."
Here is my code.
$(document).ready(function() {
$('#x').click(function() {
$('.y').toggle("slide");
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="x">Click</div>
<div class="y" style="display: none;">
<div class="container">
<form action="insertzunanja.php" method="POST" id="x">
<input type="hidden" name="narocilo" value="0.1412312">
<input type="hidden" name="id" value="id-1">
<input type="text" name="dolzina" style="width:49%;" placeholder="Dolzina (v cm)">
<input type="text" name="sirina" style="width:49%;" placeholder="Sirina (v cm)">
<input type="text" name="kolicina" value="1" style="width:49%;" placeholder="Kolicina">
<input type="text" name="opombe" style="width:49%;" placeholder="Opombe">
<input type="submit" value="Send">
</form>
</div>
</div>
Thanks and best regards.
You can use AJAX call to send the data to php file instead of form action. According to your code you will have something like this:
<div id="x">Dodaj</div>
<div class="y" style="display: none;">
<div class="container">
<input type="hidden" name="narocilo" value="<?php echo $randomNum; ?>">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="text" name="dolzina" style="width:49%;" placeholder="Dolzina (v cm)">
<input type="text" name="sirina" style="width:49%;" placeholder="sirina (v cm)">
<input type="text" name="kolicina" value="1" style="width:49%;" placeholder="Kolicina">
<input type="text" name="opombe" style="width:49%;" placeholder="Opombe">
<input id="sub" type="submit" value="Send">
</div>
</div>
$(document).ready(function(){
$('#x').click(function() {
$('.y').toggle("slide");
});
});
$("sub").click(function(){
$.post("insertzunanja.php",
{
dolzina: $("input[name=dolzina]"),
sirin: $("input[name=sirina]")
},
function(){
$("input[name=dolzina]").val("");
$("input[name=sirina]").val("");
if($('.y').is( ":hidden" )) {
$('.y').toggle("slide");
}
});
});
Basically, when you click on button you call php with AJAX POST request passing two values dolzina and sirin retrieved by the html code(note: you have more values to pass so change it accordingly) to php file. Jquery deletes the values of the input fields and check if input fields are shown. If not the inputs fields are shown.
If you are using PHP to process the form submission and generate the code in your question, and you always want the form to be displayed after submission, you can do this:
At the PHP code identify submission (e.g. isset($_REQUEST['id']) ).
[if #1 is true] On generating jQuery code, add $('.y').show(); within the ready function (but separated from the existing click function).
Example:
<?php
// your existing code...
?>
$(document).ready(function() {
<?= ( isset($_REQUEST['id']) ? '$(".y").show();' : '' ); ?>
$('#x').click(function() {
$('.y').toggle("slide");
});
});
<?php
// your existing code...
?>
Input field inside a while condition i'm displaying the tab in which tab values are fetched from table red_digid_info
<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');"">
<div class="row">
<label for="fromdate" class="col-sm-1 control-label"> FROM DATE </label>
<label for="todate" class="col-sm-1 control-label" style="margin-left: 4cm;"> TO DATE </label>
</div>
<div class="row">
<div class="col-sm-1">
<div class="input-group">
<input type="text" class="form-control" id="fromdatepicker" name="fromdate" placeholder="yyyy-mm-dd" style="width:200px;height:33px;">
<span class="input-group-addon"><i class='glyphicon glyphicon-calendar'></i></span>
</div>
</div>
<div class="col-sm-1" style="margin-left:4cm">
<div class="input-group">
<input type="text" class="form-control" id="todatepicker" name="todate" placeholder="yyyy-mm-dd" style="width:200px;height:33px;">
<span class="input-group-addon"><i class='glyphicon glyphicon-calendar'></i></span>
</div>
</div>
<div class="col-sm-offset-2 col-sm-2">
<input type="submit" value="ISP Status" class='btn btn-purple btn-rounded w-md m-b-5' name="isp_button">
<input type="hidden" value="1" name="pointer">
<button type="button" class="btn btn-pink btn-rounded w-md m-b-5" onclick="resetforms('form_isp_status')">Reset</button>
</div>
</div>
<div class="row">
<label for="isp" class="col-sm-1 control-label"> SELECT ISP</label>
</div><div class="row">
<div class="tab">
<?php
$isp_tab = mysql_query("SELECT DISTINCT(`isp`) FROM `red_dgid_info`");
while ($result = mysql_fetch_array($isp_tab)) {
$isp_value = $result[0];
echo '<input class="tablinks ion-social-rss" type="submit" name="isp_value[]" value="'.$isp_value.'">';
//echo '<input type="hidden" name="isp_hidden_value[]" value="'.$isp_value.'">';
}
?>
</div>
</div></form>
if i click any one value of a tab i ve to display the tab content so i need the value of submit button in php post method
if($_REQUEST['pointer'] ==1)
{
var_dump($_POST);
//-------status criteria given---------------------//
//-----------isp tab submiited--------------//
if(isset($_POST['isp_value']))
{
print_r($_POST['isp_value']);
$isp=$_POST['isp_value'];
}
//------------------end----------------------//
//----------hidden value array--------------//
/*$data = $_POST['isp_hidden_value'];
foreach($data as $isp)
{
echo "isp_hidden =".$isp;
}
//---------------another way----------------//
$isp_hidden = $_POST['isp_hidden_value'][$isp];*/
//--------------end------------------------//
$date= date("Y-m-d");;
$fromdatepicker =$_POST['fromdate'];
$todatepicker =$_POST['todate'];
exit;
}
if(isset($_POST['isp_value'])) //this if condition fails isp_value is not set don't know the reason and solution for it
submit function
function submit_isp_status(formId) {
if($("#"+formId).valid() == true) {
$.ajax({
type: 'POST',
url: 'webxstatus.php', //same page
data: $("#"+formId).serialize(),
success: function(data) {
..........
}
});
}
}
I'm stuck with this for past 2 days anyone help me to solve this.
you need to change your input name to array like this isp_value[] so only you can get the value which submit button you clicked otherwise you will get last value only .
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value[]' value='$isp_value'></input>"
PHP :
print_r($_POST['isp_value']);
And also minor single quotes problem in your isp_hidden_value
echo '<input type="hidden" name="isp_hidden_value[]" value="'.$isp_value.'">';
note:
if you need currently clicked submit button value means . don't use hidden field it will collect all values . just insert the value in submit button it will collect only curently clicked element value only as a array
Try this example :
<?php
if(isset($_POST['xyz']))
{
print_r($_POST);
}
?>
<form action="" method="post">
<input type="submit" name="xyz[]" value="1" >
<input type="submit" name="xyz[]" value="2" >
</form>
<?php $isp_tab=mysql_query("select distinct(isp) from red_dgid_info");
while($result=mysql_fetch_array($isp_tab))
{
echo'<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');">';
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'></input>";
echo '<input type="hidden" name="isp_hidden_value" value='$isp_value'>';
echo'</form>';
}?>
put form inside while loop
while($result=mysql_fetch_array($isp_tab))
{
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'></input>";
echo '<input type="hidden" name="isp_hidden_value[]" value='$isp_value'>';
}?>
$data =$_POST['isp_hidden_value'];
foreach($data as $isp)
{
echo "isp_hidden"=$isp;
}
Use input field 'isp_hidden_value' as array and fetch values using foreach
You need to do some changes in your code, and after that i hope it will work perfectly:
Change hidden field
from:
echo '<input type="hidden" name="isp_hidden_value" value="$isp_value">';
to:
echo "<input type='hidden' name='isp_hidden_value[$isp_value]' value='" . $isp_value . "'>";
In the post method change value assignment of hidden field
from:
$isp_hidden = $_POST['isp_hidden_value'];
to:
$isp_hidden = $_POST['isp_hidden_value'][$isp];
Rest should work fine.
Logic behind this change is to use array when using same name for multiple input types. Here you are using a flat variable which will hold only one value, which will get assigned at the end. If you use array it will hold multiple values and allows you to get your desired result.
You don't need a hidden field for this. A button with a name should send it's value.
<?php
var_dump($_POST);
?>
<form method="POST" action="">
<div class="row">
<div class="tab">
<input type="submit" name="button" value="test1">
<input type="submit" name="button" value="test2">
</div>
</div> </form>
Will tell me that $_POST['button'] is either test1 or test2
Which means that the following should work
<form method="POST" action="" id="form_isp_status" onsubmit="submit_isp_status('form_isp_status');"">
<div class="row">
<div class="tab">
<?php $isp_tab=mysql_query("select distinct(isp) from red_dgid_info");
while($result=mysql_fetch_array($isp_tab))
{
$isp_value =$result[0];
echo "<input class='tablinks ion-radio-waves' type='submit' name='isp_value' value='$isp_value'>";
// note: input is a empty tag, meaning that it is not to be closed using </input> but by using />, which
// is only relevant for XHTML
}?>
</div>
</div> </form>
Edit:
On the server side the only thing you have to do is use the value of $_POST['isp_value'].
var_dump($_POST); // only to check the POST variable during debugging
if (isset($_POST['isp_value'])) { // Possibly not needed if there are no other submit buttons in the from, but good practice to check if something exists
// do something using $_POST['isp_value']
}
As a sidenote: mysql_* has been deprecated in PHP 5.5.0 and been removed in PHP 7.0. It is recommended to either use MySQLi or PDO instead
Ive saved form data with ajax and php, reusing the data from the database.
However the way I am approaching this is different, there is no database, so some insight would be great.
I am emailing form data, all the data is just simple checkboxes, the values are either 0 or 1. When the user refreshes the page id like to keep the checked values.
I guess without a database I would need to use cookies, and the only way to avoid cookies would be ajax and a database (strictly my logic, not sure if true), this is why I am asking, I just want a simple solution.
Form snippet:
<input name="sharks" type="hidden" value="0">
<input name="sharks" type="checkbox" value="1" id="sharks" '.$VALUE ? ' checked="checked"' : ''.'>
The php part of that input is shaky, Id like to question whether the value is 0 or 1, if its 1 then its checked if its 0 then empty.
Getting it from the database would be easier but not so sure since there is no database, Im guessing cookies would come into place.
Sorry if this last part is shaky but im a little unsure and dont know where to look.
Using Sessions:
session_start();
if(isset($_POST['submit'])) {
if(isset($_POST['personalization_result'])) {
$_SESSION['value'] = $_POST['personalization_result']; }
else {
$_SESSION['value'] = '';
}
}
Form
<form action="<?php the_permalink(); ?>" method="post" id="question-form">
<input type="hidden" name="submit" value="1">
<?php
if ($_SESSION['value'] == 1) {
$checked = 'checked="checked"'; }
?>
<li>
<input name="personalization_result[memory_0]" type="hidden" value="0">
<input name="personalization_result[memory_0]" type="checkbox" value="1" id="personalization_result_memory_0" <?php $checked ?> >
</li>
<li>
<input name="personalization_result[memory_1]" type="hidden" value="0">
<input name="personalization_result[memory_1]" type="checkbox" value="1" id="personalization_result_memory_1" <?php $checked ?> >
</li>
<li>
<input name="personalization_result[memory_2]" type="hidden" value="0">
<input name="personalization_result[memory_2]" type="checkbox" value="1" id="personalization_result_memory_2" <?php $checked ?> >
</li>
This code stores the data in a session:
<?php
session_start();
if(isset($_POST['submit']))
{
if(isset($_POST['sharks']))
{
$_SESSION['value'] = $_POST['sharks'];
}
else
{
$_SESSION['value'] = '';
}
}
?>
<form action="" method="POST">
<?php
print '<input name="sharks" type="checkbox" value="1" id="sharks" ';
if ($_SESSION['value'] == 1)
{
print ' checked="checked"';
}
print ">";
?>
<br>
<input type="submit" name="submit" value="Save" />
</form>
Worked for me, keeping the checkbox checked after I closed and opened the browser again. After some testing I added a rather complex if to avoid the undefined variable notice. Now the set part seems robust.
You can either use session or cookie. Basically you will access using $_COOKIE or $_SESSION. I would rather say that this is easier than using a database.
For cookies have a look at setcookie (http://www.php.net/setcookie)
For sessions: http://php.net/manual/en/book.session.php
I would use local storage or session storage, this is a client side memory storage location that persists even if the page is refreshed, it is integrated into html5.
Here is a nice tutorial about it:
http://www.w3schools.com/html/html5_webstorage.asp
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Persist checkboxes 1</title>
<script>
window.jQuery || document.write("<script src='jquery-.1.1.js'><\/script>");
</script>
<script>
$(document).ready(function()
{
$('#me').click(function()
{
var seloption = $('input[type="checkbox"]:checked');
if (seloption.length > 0)
{
var abc = seloption.length + "checked \n";
//alert(abc);
i = 0;
seloption.each(function()
{
abc = abc + $(this).text(seloption[i]) + "<br>";
}
);
$('#msg').html(abc);
}
}
);
}
);
</script>
</head>
<body>
<div>
<label for="option1">Option 1</label>
<input type="checkbox" id="option1">
</div>
<div>
<label for="option2">Option 2</label>
<input type="checkbox" id="option2">
</div>
<div>
<label for="option3">Option 3</label>
<input type="checkbox" id="option3">
</div>
<div>
<label for="option4">Option 4</label>
<input type="checkbox" id="option4">
</div>
<div>
<label for="option5">Option 5</label>
<input type="checkbox" id="option5">
</div>
<div>
<label for="option6">Option 6</label>
<input type="checkbox" id="option6">
</div>
<div>
<label for="option7">Option 7</label>
<input type="checkbox" id="option7">
</div>
<div>
<label for="option8">Option 8</label>
<input type="checkbox" id="option8">
</div>
<div>
<label for="option9">Option 9</label>
<input type="checkbox" id="option9">
</div>
<button type="button" id="me">Submit</button>
<div id="msg">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/jquery.cookie/1.4.0/jquery.cookie.min.js"></script>
<script>
$(":checkbox").on("change", function() {
var checkboxValues = {};
$(":checkbox").each(function() {
checkboxValues[this.id] = this.checked;
});
$.cookie('checkboxValues', checkboxValues, {expires: 1, path: '/'});
});
function repopulateCheckboxes() {
var checkboxValues = $.cookie('checkboxValues');
if (checkboxValues) {
Object.keys(checkboxValues).forEach(function(element) {
var checked = checkboxValues[element];
$("#" + element).prop('checked', checked);
});
}
}
$.cookie.json = true;
repopulateCheckboxes();
</script>
</body>
</html>
I am trying to set up a form that users of my website - piciscan.co.uk - will use to order photobooks. I would like to offer them some options when ordering their photobooks, and on submission of the form, I would like the customer to be redirected to the relevant page of my separate, shop website - piciscanshop.co.uk.
For example, should the user want to order a portrait photobook, in layout 4, with printed page numbers, they should be redirected to piciscanshop.co.uk/portrait-layout4-pagenums-photobook.
So far, I have the html for a form, and believe that it is possible, with some php, to make what I am looking for, happen.
Here is the html code:
<form id="layoutSelector" method="get" action="layoutSelector.php">
<fieldset>
<input type="radio" name="aspect" id="layoutAspectPortrait" value="portrait">
<label for="layoutAspectPortrait">Portrait</label>
<br>
<input type="radio" name="aspect" id="layoutAspectPortrait" value="landscape" checked="checked">
<label for="layoutAspectPortrait">Landscape</label>
</fieldset>
<fieldset>
<input type="radio" name="layout" id="layoutNumber1" value="layout1">
<label for="layoutNumber1">Layout 1</label>
<br>
<input type="radio" name="layout" id="layoutNumber2" value="layout2">
<label for="layoutNumber2">Layout 2</label>
<br>
<input type="radio" name="layout" id="layoutNumber3" value="layout3" checked="checked">
<label for="layoutNumber3">Layout 3</label>
<br>
<input type="radio" name="layout" id="layoutNumber4" value="layout4">
<label for="layoutNumber4">Layout 4</label>
</fieldset>
<fieldset>
<input type="radio" name="pageNums" id="layoutPageNums" value="pageNums">
<label for="layoutPageNums">Page Numbers</label>
<br>
<input type="radio" name="pageNums" id="layoutNoPageNums" value="" checked="checked">
<label for="layoutNoPageNums">No page numbers</label>
<br>
</fieldset>
<div class="submitsAndHiddens">
<input type="submit" value="Submit">
</div>
</form>
So, I guess what I am looking for help with is: how to write layoutSelector.php.
Any help would be most appreciated.
In layoutSelector.php, get the form data via $_GET['field_name_here'], process it however you want (use var_dump($_GET); to see everything that was passed in). Then, redirect to the appropriate page using die(header('Location: other_page.php'));.
So for your example in your question, layoutSelector.php might look something like this:
<?php
if ($_GET['layout'] === 'layout4' && $_GET['pageNums'] === 'layoutPageNums') {
die(header('Location: /portrait-layout4-pagenums-photobook'));
}
?>
Or, if all your pages are laid out this way, you could probably just do something like this:
<?php
die(header('Location: /'. $_GET['aspect'] .'-'. $_GET['layout'] .'-'. $_GET['pageNums'] .'-photobook'));
?>
An even better solution would be to check these values via JavaScript when the form is submitted and change the form action, so no redirecting is needed (which would be faster).
in layoutSelector.php put this code
$page = $_GET['aspect'] . "-" . $_GET['layout'] . '-' . $_GET['pageNums'] . '-' .'photobook';
header('Location : '. 'http://piciscanshop.co.uk/'.$page);
Ok here is my problem, and all of my 'dirty' code. This isn't my production code but just trying to make it work at the moment.
Basically what I need is when a user selects the Not Ok radio button it displays the textarea for that unique set which it doesn't do right now when I select Not Ok it gives the textarea's for all the entries which right now is about 13 sets of questions that get generated dynamically from a mysql database at the moment. I have a feeling it has to do something with unique id's that are either in the wrong place in my code now, or just simply aren't there at all. Any help is appreciated greatly.
<div data-role="collapsible" data-theme="b" data-content-theme="c">
<h3>Vehicle Check Information</h3>
<?php
$query = mysql_query("SELECT * FROM vehicle_q");
while($row = mysql_fetch_array($query)) {
$q_title = $row['title'];
$q_id = $row['id'];
?>
<div data-role="fieldcontain" style="border:0;">
<fieldset data-role="controlgroup">
<legend><?php echo $q_title; ?>:</legend>
<input type="radio" name="help[]" id="checkbox-1a" value="Ok" />
<label for="checkbox-1a">Ok</label>
<input type="radio" name="help[]" id="checkbox-2a" value="Not Ok" />
<label for="checkbox-2a">Not Ok</label>
</fieldset>
<div id="hidden_text-<?php echo $q_id; ?>" style="display:none;">
<script>
$(document).ready(function(){
$(":radio:eq(1)").click(function(){
$("#hidden_text-<?php echo $q_id; ?>").show(500);
});
$(":radio:eq(0)").click(function(){
$("#hidden_text-<?php echo $q_id; ?>").hide(500);
});
});
</script>
<fieldset data-role="fieldcontain">
<label for="<?php echo $q_title; ?>_t">Explain the Deficiency(If any):</label>
<textarea name="text_a[]" id="<?php echo $q_title; ?>_t"></textarea>
</fieldset>
</div>
</div>
<input type="hidden" name="q_title1[]" value="<?php echo $q_title; ?>" />
<?php
}
?>
</div>
The other 2 answers are ways to fix your issue. As a side, here is possibly why it is happening. When you are using -
$(":radio:eq(1)").click(function()
$(":radio:eq(0)").click(function()
You are using a click listener that just checks for if 'any' radio button with that index position was clicked on your page. So any button with 1 index position will make every $(":radio:eq(1)").click(function() execute.
Edit -
You would want to change your radio button ids, as (1) they will not be unique as you repeat them with each while() loop, and (2) you could use it to check if that specific radio buttton was clicked.
Try changing it to -
...
<input type="radio" name="help[]" id="checkbox-1a-<?php echo $q_id; ?>" value="Ok" />
<label for="checkbox-1a">Ok</label>
<input type="radio" name="help[]" id="checkbox-2a-<?php echo $q_id; ?>" value="Not Ok" />
<label for="checkbox-2a">Not Ok</label>
</fieldset>
<div id="hidden_text-<?php echo $q_id; ?>" style="display:none;">
<script>
$(document).ready(function(){
$("#checkbox-2a-<?php echo $q_id; ?>").click(function(){
$("#hidden_text-<?php echo $q_id; ?>").show(500);
});
$("#checkbox-1a-<?php echo $q_id; ?>").click(function(){
$("#hidden_text-<?php echo $q_id; ?>").hide(500);
});
});
</script>
The easiest way that I have found to show hide elements based off of radio values is to serve up an onchange event based on the id of the element (which you already have). In your case, since you only have two radios based off the same name, the easiest way is a simple if/else statement. Something like:
<script type="text/javascript">
$(function(){
$('#checkbox-1a').change(function(){
if($(this).attr('checked')){
$('#hidden-text-<?php echo $q_id;?>').hide(500);
}else{
$('#hidden-text-<?php echo $q_id;?>').show(500);
}
});
});
</script>
Where we state when #checkbox-1a is changed: if the element is checked (selected), then do something (in your case hide something), otherwise do something else (in your case show something).
Try something like:
<div data-role="collapsible" data-theme="b" data-content-theme="c">
<h3>Vehicle Check Information</h3>
<?php
$query = mysql_query("SELECT id,title FROM vehicle_q");
while($row = mysql_fetch_array($query)) {
$q_title = $row['title'];
$q_id = $row['id'];
?>
<div data-role="fieldcontain" style="border:0;" class="groupings">
<fieldset data-role="controlgroup">
<legend><?=$q_title?>:</legend>
<input type="radio" name="help[]" id="checkbox-<?=$q_id?>-1a" value="Ok" />
<label for="checkbox-<?=$q_id?>-1a">Ok</label>
<input type="radio" name="help[]" id="checkbox-<?=$q_id?>-2a" value="Not Ok" />
<label for="checkbox-<?=$q_id?>-2a">Not Ok</label>
</fieldset>
<div id="hidden_text-<?=$q_id?>" class="hiddenText" style="display:none;">
<fieldset data-role="fieldcontain">
<label for="<?=$q_title?>_t">Explain the Deficiency(If any):</label>
<textarea name="text_<?=$q_id?>_a[]" id="<?=$q_title?>_t"></textarea>
</fieldset>
</div>
</div>
<input type="hidden" name="q_title1[]" value="<?php echo $q_title; ?>" />
<?php
}
?>
</div>
<script>
$(document).ready(function(){
$(".groupings input:radio").click(function(){
if (this.value == "Ok") {
$(this).parent().next('.hiddenText').show(500);
} else {
$(this).parent().next('.hiddenText').hide(500);
}
});
});
</script>
This is untested, but the script only needs to be declared once and it will apply to the rest relative to the radio button.