In my HTML, the input value is populated by user selection and stored in array format (e.g.
45[45, 6, 33], 67[67,2,5] and so on..
). Essentially, the value will look like this:
<input id="question_string" type="hidden" value="{}">
<input class="submit_updates" name="commit" type="submit" value="Process">
I want to disable the submit button or display an alert message saying 'Select all values' if the input does not contain any arrays within the {}
.
Updated:
var question_hash_element = document.getElementById('question_string');
var question_hash = JSON.parse(question_hash_element.value);
var myArray = new Array();
myArray[0] = window.batch_question_id;
myArray[1] = window.answer_id || window.answer_text || window.batch_answer_checkbox
myArray[2] = window.build_id
This code above stores the values in the {}
. I only want to enable the form submission once all fields are selected. If the values are empty within {}
, the button should remain disabled; otherwise, it should be enabled.
I attempted the following:
$('.submit_updates').click(function () {
if ($('#question_string') == {}) {
return false;
alert("Select all the Values");
} else {
return true;
}
});
Unfortunately, this approach is not functioning correctly.
Any assistance would be greatly appreciated! Thank you