Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

277
Vistas
how to extract extract the weight number without g using javascript

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>

<p>What i have</p>
<input value="1475g - 1500g" /><br>
<p>what do i need.</p>

<input style="width:50px;" value="1475" /><span>g - </span><input style="width:50px;" value="1500" /><span>g</span>


</body>
</html>

Description

  1. From the above code in first text box i have been setting value of '1475g - 1500g' but i need to do is show only the weight numbers in two different input box

for example

  1. string val = 1475g - 1500g;
  2. string Separated_value1=1475;
  3. string Separated_value2=1500;
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use split and replace.

const input = document.querySelector("input").value; // add an ID or class or something, this is just for demo purposes

const [ seperated1, seperated2 ] = input.replace(/g/g, "").split(" - "); // First regular expression removes all "g"s from the string. Split turns the string into an array using " - " as a delimiter

console.log(seperated1, seperated2);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use this:

let val = '1475g - 1500g';
val = val.replace(/g| /g, '');
val = val.split('-');
console.log(val[0], val[1]);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda