This might be a very easy question, but I find it confusing.
How do I run myFunc() if textField_1 is not empty?
Excicute .on('click', '#openButton', myFunc) if ($('#textField_1').val()!="") ?
Check inside the handler:
.on('click', '#openButton', function() {
if( !$('#textField_1').val().trim().length ) myFunc(); //thanks to @Mike for the suggestion on trim and length, see comments
})
Refer below code
<div>
<div>
<input type="text" id="text"/>
<input type="button" value="click" id="click"/>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#click").click(function () {
if ($("#text").val() != '') {
myfunction();
}
});
});
function myfunction() {
alert($("#text").val());
}
</script>
You can test $('#textField_1').val() in an if statement. If it's empty, it'll be treated as false, otherwise it's treated as true.
JS (jQuery):
$('#openButton').on('click', function () {
if ($('#textField_1').val()) {
myFunc();
}
});
Here's a fiddle.
myFunc?