HTML
<input class="jet-form__field text-field " value="" name="points_on_deed" id="points_on_deed" type="text" data-field-name="points_on_deed"> <input class="jet-form__field text-field " value="" name="price_per_point" id="price_per_point" type="text" data-field-name="price_per_point"> <input class="jet-form__field text-field " value="" name="price" id="price" type="text" data-field-name="price"> <select name="mason_title_florida" data-field-name="mason_title_florida" id="mason_title_florida" data-default-val="" class="jet-form__field select-field" required="required"> <option value="" selected="">Set Price...</option> <option value="508">5000</option> <option value="515">6000</option> <option value="522">7000</option> <option value="529">8000</option> <option value="536">9000</option> <option value="543">10000</option> <option value="550">11000</option>JavaScript
var flclosing = document.getElementById("mason_title_florida"); var caclosing = document.getElementById("mason_title_california"); var scclosing = document.getElementById("mason_title-south_carolina"); var price = document.getElementById("price"); var points = document.getElementById("points_on_deed"); var ppp = document.getElementById("price_per_point"); points.addEventListener("keyup", setPrice); ppp.addEventListener("keyup", setPrice); function setPrice() { price.value = points.value*ppp.value; setFLClosingCost(); } function setFLClosingCost() { var roundedPrice = Math.ceil(price.value/1000)*1000; if (roundedPrice <= 5000){ roundedPrice = 5000; } if (flclosing.style.display != "none") { flclosing.selectedIndex = roundedPrice; } }Estoy tratando de seleccionar mi opción según el texto de la etiqueta y no el valor.
El desglose: Introducir puntos: 100 Introducir precio por punto: 100 El precio se calcula con setPrice().
La siguiente función redondea ese precio para que coincida con mis etiquetas de campo de selección.
¿Cómo puedo seleccionar la opción basada en el número redondeado?
Si mi precio es 10.915. Redondeará mi valor a 11.000 (funciona hasta este punto). ¿Cómo puedo seleccionar la etiqueta 11000 de mi lista de selección?
Estoy ejecutando este script en Wordpress usando jetengine y elementor. Tengo una configuración de glosario para mi campo de selección.
yo actualice
flclosing.selectedIndex = roundedPrice;
a
flclosing.selectedIndex = roundedPrice / 1000 - 4;
var flclosing = document.getElementById("mason_title_florida"); var caclosing = document.getElementById("mason_title_california"); var scclosing = document.getElementById("mason_title-south_carolina"); var price = document.getElementById("price"); var points = document.getElementById("points_on_deed"); var ppp = document.getElementById("price_per_point"); points.addEventListener("keyup", setPrice); ppp.addEventListener("keyup", setPrice); function setPrice() { price.value = points.value * ppp.value; setFLClosingCost(); } function setFLClosingCost() { var roundedPrice = Math.ceil(price.value/1000)*1000; if (roundedPrice <= 5000){ roundedPrice = 5000; } if (flclosing.style.display != "none") { flclosing.selectedIndex = roundedPrice / 1000 - 4; } } <input class="jet-form__field text-field " value="" name="points_on_deed" id="points_on_deed" type="text" data-field-name="points_on_deed"> <input class="jet-form__field text-field " value="" name="price_per_point" id="price_per_point" type="text" data-field-name="price_per_point"> <input class="jet-form__field text-field " value="" name="price" id="price" type="text" data-field-name="price"> <select name="mason_title_florida" data-field-name="mason_title_florida" id="mason_title_florida" data-default-val="" class="jet-form__field select-field" required="required"> <option value="" selected="">Set Price...</option> <option value="508">5000</option> <option value="515">6000</option> <option value="522">7000</option> <option value="529">8000</option> <option value="536">9000</option> <option value="543">10000</option> <option value="550">11000</option> </select>