I am hoping you can help me, I am trying to retrieve data from a MySQL database and update a checkbox, radio button and text area. At the moment all I can seem to update is input fields.
On the homepage there's a table which initiates using PHP and using a while loop populates data from MySQL. One of the columns there is a form with hidden fields that contain the primary key for each row of data returned by the SQL, also a button.
When selecting the button the following Ajax call is made to load data into a form.
I could not figure out the following post How to check radio buttons and I don't want to select a button to change the radio buttons or check box.
$(function() {
$(".mlsload").click(function() {
var id = ($(this).val());
var mlsid = $("#mlsidbutton"+id).val();
var odrid = $("#odridbutton"+id).val();
var dataString = 'drop_3='+ mlsid + '&drop_2=' + odrid;
$.ajax({
type: "POST",
async: false,
url: "../EPRS/functions/reportsdatamls.php",
dataType: 'json',
data: dataString,
success: function( data ) {
for(var dataString in data) {
$("input#"+dataString).val( data[dataString] );
}
}
});
<?php
$mlsid = $_POST['drop_3']; // Reads the value of drop 3 form the project reports section - this identifies the milestone to load
//mysql_connect("localhost", "root", "") or
//die("Could not connect: " . mysql_error());
//mysql_select_db("miranda_prj_report");
include('../mysqlconn/db.php');
// loads data from my SQL table to enter into an array. The array is then used to populate field dataon http forms
$query = "SELECT * FROM `miranda_prj_report`.`prj_mls_milestones` where mls_id = $mlsid";
$result = mysql_query($query,$sql_con);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
// Inserts all values from the view into the following veriables
$mlsid = $row['mls_id'];
$odrid = $row['odr_id'];
$mlsterms = $row['mls_Milestone_Terms'];
$mlsvalue = $row['mls_Milestone_Value'];
$mlspercentage = $row['mls_Milestone_Percentage'];
$mlsbaselinedate = $row['mls_Baseline_Date'];
$mlsexpecteddate = $row['mls_Expected_Date'];
$mlsstatus = $row['mls_Milestone_Status'];
$mlsrisk = $row['mls_Milestone_Risk'];
$mlsnotes = $row['mls_Milestone_Notes'];
$AcceptanceTrigger = $row['mls_Acceptance_Trigger'];
$MLSBillable = $row['mls_Billable'];
// Creates an Array and update the Fields representing these values on the project reports page under the orders tab
$mlsarr = array(
'MilestoneDescription'=> $mlsterms,
'MilestoneRiskDB' => $mlsrisk,
'MilestoneStatus' => $mlsstatus,
'MilestoneBaselineDate' => $mlsbaselinedate,
'MilestoneExpectedDate' => $mlsexpecteddate,
'MilestoneNotes' => $mlsnotes,
'MilestoneID'=> $mlsid,
'MilestonePercentage'=> $mlspercentage,
'MilestoneValue'=> $mlsvalue,
'AcceptanceTrigger'=> $AcceptanceTrigger,
'MLSBillable' => $Billable == "1",
);
echo json_encode( $mlsarr );
mysql_close();
?>
The JSON Echo Data:
{"MilestoneDescription":"50% on shipment of Goods","MilestoneRiskDB":"Green","MilestoneStatus":"Complete","MilestoneBaselineDate":"2014-09-12","MilestoneExpectedDate":"2014-09-12","MilestoneNotes":"Shipped on 12th Sept","MilestoneID":"1599","MilestonePercentage":"102945.00","MilestoneValue":"51472.50","AcceptanceTrigger":"","MLSBillable":true}
Above you can see the MLSBillable is set to true.
In the HTML form there are many fields which are populated fine but only if the field is type input. I need to toggle the checkbox and radio buttons but cant work out how.
<label for="MLSBillable">Billable Milestone </label><input type="checkbox" name="MLSBillable" ID="MLSBillable"/>
<label for="MilestoneRisk">Update Milestone Risk</label>
<input type="radio" name="MilestoneRisk" value="Red" id="MilestoneRisk_0" /><label for="MilestoneRisk">Red</label>
<input type="radio" name="MilestoneRisk" value="Amber" id="MilestoneRisk_1" /><label for="MilestoneRisk">Amber</label>
<input type="radio" name="MilestoneRisk" value="Green" id="MilestoneRisk_2" /><label for="MilestoneRisk">Green</label>
Finally any examples of how I can update a textarea would also help.
Thank you very much for your support.