long time reader and have used this site for help for years. Most of my problems I have been able to solve using this site but this one is killing me as it is delaying the release to my customer (which should have been done a month ago).
This isn't the exact code but should show what I am looking to do. My problem is that when a condition isn't met after clicking the "Submit" button it is clearing all of the fields rather than allowing the user to continue off where they were.
Example code:
$(document).on('click','#btngetinfo',function(e){
var gettheinfo = 0;
e.stopImmediatePropagation();
var weight1 = $("#txtweight1").val();
var length1 = $("#txtlength1").val();
var width1 = $("#txtwidth1").val();
var height1 = $("#txtheight1").val();
//Conditional stuff thrown in here
if (height1 != 0 && height1 != "0" && height1 != "" && height1 < 98) {
gettheinfo = 1;
}
if (gettheinfo == 1){
//Run AJAX code
console.log("Variables:", weight1, length1, width1, height1);
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" id="txtweight1" class="form-control">
<input type="text" id="txtlength1" class="form-control">
<input type="text" id="txtwidth1" class="form-control">
<input type="text" id="txtheight1" class="form-control">
<button type="button" class="btn gflbtn btn-block" id="btngetinfo">Submit</button>
Any help would be appreciated because I am losing hours and hours on this. Thank you in advance!