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

101
Vistas
how to change input box value in html when selectbox is selected without changing the select box value

i am trying to integrate payu payment gateway in my website so when a user selects the product info in my form, the amount should change accordingly, I have done the following:

function myFunction(e) {
    document.getElementById("myText").value = e.target.value
}
<select name="productinfo" onchange="myFunction(event)" class="form-control">
  <option value="<?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo']; ?>" disabled selected>Choose Database Type</option>
  <option value="26,999">X 1.5</option>
  <option value="28,999">X 2.5</option>
  <option value="32,999">X 3.5</option>
  <option value="35,999">X 4.5</option>
</select>

<input type="text" name="amount" id="myText" class="form-control"   value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount']; ?>" readonly>

here the amount is being changed according to product select and am able to pass it to pay, what I want is the product info also to be passed like value="X2" in the form, is there any way to do it,please help, thanks in advance

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Here try this:

function myFunction(e) {
    document.getElementById("myText").value = e.options[e.selectedIndex].getAttribute('data-price');
}
<select name="productinfo" onchange="myFunction(this)" class="form-control">
  <option value="<?php echo (empty($posted['productinfo'])) ? '' : $posted['productinfo']; ?>" disabled selected>Choose Database Type</option>
  <option value="X 1.5" data-price="26,999">X 1.5</option>
  <option value="X 2.5" data-price="28,999">X 2.5</option>
  <option value="X 3.5" data-price="32,999">X 3.5</option>
  <option value="X 4.5" data-price="35,999">X 4.5</option>
</select>

<input type="text" name="amount" id="myText" class="form-control"   value="<?php echo (empty($posted['amount'])) ? '' : $posted['amount']; ?>" readonly>

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