Reputation: 741
Below I have a form which contains four text inputs:
<form id='updateForm'>
<p><strong>Current Assessment's Date/Start Time:</strong></p>
<table>
<tr>
<th> </th>
<td><input type='text' id='currentId' name='Idcurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Assessment:</th>
<td><input type='text' id='currentAssessment' name='Assessmentcurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Date:</th>
<td><input type='text' id='currentDate' name='Datecurrent' readonly='readonly' value='' /> </td>
</tr>
<tr>
<th>Start Time:</th>
<td><input type='text' id='currentTime' name='Timecurrent' readonly='readonly' value=''/> </td>
</tr>
</table>
</form>
Now below I have a drop down option which goes at:
$sessionHTML .= sprintf("<option value='%s' style='color: %s'>%s - %s - %s</option>", $dbSessionId, $class, $dbSessionName, date("d-m-Y",strtotime($dbSessionDate)), date("H:i",strtotime($dbSessionTime))) . PHP_EOL;
Now what I am doing is that the values displayed in the drop down menu is displayed in their relevant text inputs using this code below:
$('#sessionsDrop').change( function(){
if( $(this).val() !== '' ){
var text = $(this).find('option:selected').text();
var split = text.split(' - ');
$('#currentAssessment').val( split[0] );
$('#currentDate').val( split[1] );
$('#currentTime').val( split[2] );
}
});
But the only problem I am having is how do I display the value of the option which is <option value='%s' ... $dbSessionId ...
to be displayed in the text input #currentId
?
Upvotes: 0
Views: 117