Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

302
Views
JS Select an option base on the label value/innerText

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;
       }
   }

I am trying to select my option based on the label text and not the value.

The breakdown: Enter Points: 100 Enter Price Per Point: 100 Price is Calculated with setPrice().

The next function rounds that price so it matches my select field labels.

How can I select the option based on the rounded number?

If my price is 10,915. It will round my value to 11,000 (it works up to this point). How can I select the label 11000 from my select list?

I am running this script in Wordpress using jetengine and elementor. I have a glossary setup for my select field.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I updated

flclosing.selectedIndex = roundedPrice;

to

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>

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!