Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

209
Visualizações
How would I be able to extract the words in my label, including the space in between words but not any additional spaces afterwards?

I'm currently lost as to how I would be able to properly use the label in my HTML as variables for my JS.

[HTML]
<div> <!--Main Toppings-->
  <label for = "mtop"> Main Toppings: </label>
  <select name="mainToppings" id = "toppingsoption" required>
  <option disabled selected id = 'emptyoption'> -- select an option -- </option>
  <option id='pepperoniOverload' class = "mtopchoice">Pepperoni Overload - &#8369 100</option>
  <option id='hawaiian' class = "mtopchoice">Hawaiian - &#8369 50</option>
  <option id='meatOverload' class = "mtopchoice">Meat Overload - &#8369 125</option>
  </select>
</div>

[JavaScript]
var toppings = document.getElementById("toppingsoption");
    if (toppings.options[toppings.selectedIndex].id == 'emptyoption') {
        var toppingsName = '';
        var toppingsValue = 0;
    } else {
        var toppingsText = toppings.options[toppings.selectedIndex].innerHTML;
        var toppingsName = toppingsText.replace(/[^a-z]/gi, '');
        var toppingsValue = parseInt(toppingsText.replace(/\D/g,''));
    
        console.log(toppingsName, toppingsValue, "getMainToppings() working");
    }

While the current code works just fine for dealing with the 'Hawaiian' option, 'Pepperoni Overload' and 'Meat Overload' is messing with the way I extract the text out of the labels. What would be the correct way so that I would be able to extract the words Pepperoni Overload and Meat Overload, maintaining the space between words but not extracting the additional spaces that follow afterwards?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Just extract everything until the - symbol. Something like the following should work:

/(.*)-/g

And then you could just extract the first group and should get what you want.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda