Answer the question
In order to leave comments, you need to log in
How to change input values when opening a modal window?
https://midavr.github.io/
When you click on the buy button, a modal window opens and in the select you can select the desired item while changing the input values, but I can’t figure out how to immediately make changes to the inputs in accordance with the selected value in the select.
The value of the select when opening is assigned like this
$(document).ready(function(){
$('a[data-toggle="modal"]').click(function(e){
e.preventDefault();
$("#field304904").val($(this).attr('data-sel'));});
});
function myFunction(e) {
document.getElementById("id_product3").value = e.target.value
if (document.getElementById("id_product3").value == 'prod 1'){
document.getElementById("id_price3").value = '299';
} else if (document.getElementById("id_product3").value == 'prod 2'){
document.getElementById("id_price3").value = '299';
} else if (document.getElementById("id_product3").value == 'prod 3'){
document.getElementById("id_price3").value = '299';
} else if (document.getElementById("id_product3").value == 'prod 8'){
document.getElementById("id_price3").value = '389';
} else if (document.getElementById("id_product3").value == 'prod 4'){
document.getElementById("id_price3").value = '449';
} else if (document.getElementById("id_product3").value == 'prod 5'){
document.getElementById("id_price3").value = '459';
} else if (document.getElementById("id_product3").value == 'prod 6'){
document.getElementById("id_price3").value = '479';
} else if (document.getElementById("id_product3").value == 'prod 7') {
document.getElementById("id_price3").value = '489';
}
}
Answer the question
In order to leave comments, you need to log in
It's best to use a pattern and not write 100500 else if, or at least loop through and make a match between cards and options in the select.
But, if you started writing like this, then the least pain will be if you do it like this:
Take the data-sel value and put it in the desired input;
Extract a numeric value from price_old/price_new and place it in the required input.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question