I have a table of data that used to use a jQuery call to display a hidden div containing an additional text input field only if one specific option was picked on a select. It looked like this - in the head of the page:
jQuery(function ($) {
$('#newSubStatus').change(function () {
$('#showhide').toggle(this.value == 'Option B');
}).change(); // To set the initial state
})
And in the body:
<select id="newSubStatus" name="newSubStatus">
<option value="Option A">Option A</option>
<option value="Option B">Option B</option>
<option value="Option C">Option C</option>
<option value="Option D">Option D</option>
<option value="Option E">Option E</option>
<option value="remove">Remove Sub-status</option>
</select><br>
<div id="showhide" style="display: none;">
<input type="text" style="width: 120px; margin-left: 40px;" name="newSubStatusExtra" value="" placeholder="Enter amount">
</div>
It worked fine. Now I am redoing this page so that the data in the table is editable using Jeditable which works perfectly with this one exception in that I cannot get it to display the hidden div by any means possible. My current code looks like this - in the head:
jQuery(function ($) {
$('#newSubStatus').change(function () {
$('#showhide').toggle(this.value == 'Option B');
}).change(); // To set the initial state
})
$(function() {
$(".edselect_subStatus").editable("./update.php?x=jiwjOijoJoihYfytfjhhiuh", {
data : '{"Option A":"Option A","Option B":"Option B","Option C":"Option C","Option D":"Option D","Option E":"Option E","REMOVE":"Remove Sub-status"}',
callback : function() {
location.reload();
},
type : 'select',
event : 'dblclick',
placeholder : '',
onblur : 'ignore',
indicator : 'Saving...',
cssclass : 'editable',
submit : 'Save',
cancel : 'Cancel',
});
});
And in the body:
<tr>
<td>Status:</td>
<td class="edselect_status" id="status"><?=$status?></td>
<td style="padding-left: 10px;">Sub-status:</td>
<td class="edselect_subStatus" id="subStatus"><?=$subStatus?>
<div id="showhide" style="display: none;"><br>
<input type="text" style="width: 120px; margin-left: 40px;" name="newSubStatusExtra" value="" placeholder="Enter amount">
</div></td>
</tr>
I understand that there is nothing to connect #newSubStatus to the select anymore to trigger it. I have tried ways to connect it to the td id it sits in, without success. I have found many other ways to make a text field to appear, but they all rely on having an id element from the originating select. Is there a way to make this work or is it too much of a JavaScript mismatch to function together?