I'm trying to add if else statement to below function.
The else statement will contain the following code so that color_update not only will be hidden but at the same time disabled when the button is not clicked.
$("#color_update").prop('disabled', true);
This is the code function:
JS
function open(elem) {
if (document.createEvent) {
var e = document.createEvent("MouseEvents");
e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
elem[0].dispatchEvent(e);
} else if (element.fireEvent) {
elem[0].fireEvent("onmousedown");
}
}
$(document).ready(function(){
$('#update').click(function(event){
event.preventDefault();
event.stopImmediatePropagation();
$('#color_update').addClass("show").focus();
open( $('#color_update') );
$("#color").prop('disabled', true);
});
CSS
#color_update {
display: none;
}
HTML
<select id="color">
<option value="Red">Red</option>
<option value="Green">Green</option>
<option value="Blue">Blue</option>
</select>
<input type="button" id="update" value="Update" />
<select id="color_update">
<option value="Red">Black</option>
<option value="Green">Purple</option>
<option value="Blue">White</option>
</select>
Please guide me. Thank you.
color_updateto be disabled initially? and Howopenfunction is relevant with the problem?open()get called? currently no where in snippet??$('#update').click(function(event){. Thecolor_updateis disabled from the start and only enabled when update button is clicked @Satpalifandelseconditionupdatebutton is clicked, theifcondition will disable thecolorand theelsewill be disabled thecolor_update. I understand that theopen()function hide and show thecolor_update. I want thecolor_updatenot only be hidden but at the same time disable. @Mayank Raj