IMPORTANT : ABOVE SNIPPET DOES WORK !
Hey guys,
I don't know why but this basic verification that input is not empty don't work :
<input type="text" class="form-control" id="title" name="title" placeholder="Title" value="<?= $title ?>" onblur="submit_basic_info()">
<input type="text" class="form-control" id="interpreter" name="interpreter" placeholder="Interpret" value="<?= $interpreter ?>" onblur="submit_basic_info()">
<button type="submit" id="submit_info_button" class="btn btn-primary">Submit</button>
<script>
function submit_basic_info() {
var get_title = document.getElementById("title").value;
var get_interpreter = document.getElementById("interpreter").value;
console.log(get_title);
console.log(get_interpreter);
if (get_title === "" || get_interpreter === "" ) {
console.log('if');
document.getElementById("submit_basic_info").innerHTML = "Please Fill-In every input";
document.getElementById('submit_info_button').disabled = true;
} else {
console.log('else');
document.getElementById("submit_basic_info").innerHTML = "";
document.getElementById('submit_info_button').disabled = false;
}
}
</script>
I can see that here in the snippet it work... but why doesn't it in my web page ? Because value is a PHP value ? Because form is inside a modal ?
I've been stuck on this for hours and I can't find any solution...
Help appreciated... :)
function submit_basic_info() {
var get_title = document.getElementById("title").value;
var get_interpreter = document.getElementById("interpreter").value;
console.log(get_title);
console.log(get_interpreter);
if (get_title === "" || get_interpreter === "") {
console.log('if');
document.getElementById("submit_basic_info").innerHTML = "Please Fill-In every input";
document.getElementById('submit_info_button').disabled = true;
} else {
console.log('else');
document.getElementById("submit_basic_info").innerHTML = "";
document.getElementById('submit_info_button').disabled = false;
}
}
<input type="text" class="form-control" id="title" name="title" placeholder="Title" value="" onblur="submit_basic_info()">
<input type="text" class="form-control" id="interpreter" name="interpreter" placeholder="Interpret" value="" onblur="submit_basic_info()">
<span id="submit_basic_info">
</span>
<button type="submit" id="submit_info_button" class="btn btn-primary">Submit</button>
My Answer:
To get the value of an element with a specific id using JavaScript, you can use the `getElementById` method to select the element and then access its `value` property. Here's an example:
html
Get Element By Id Value
In this example, we have an input element with the id "myInput" and a button that, when clicked, calls the `getValue` function. Inside the function, we use `getElementById` to select the input element and then access its `value` property to get the value. Finally, we display an alert with the value of the element.
© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Rate this post
3 of 5 based on 8976 votesComments