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

154
Vistas
How do I set a variable with a number to an html form input value attribute

I'm trying to set a numeric value to an html form's input value attribute as a variable. I'm aware that the value attribute implicitly converts to a string. How can I get the variable to be read before it is converted to a string?

<input type="hidden" name="amount" value="" id="amount">

This is the input whose value I want to set.

document.getElementById("amount").setAttribute('value', this.amount)

This is one method I've been trying.

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

0

I'm aware that the value attribute implicitly converts to a string.

It's not correct, It will return number only if you are assigning numeric value into a :value attribute.

Demo :

new Vue({
  el: '#app',
  data: {
    productName: 'xyz',
    amount: 10
  },
  methods: {
    submitForm() {
      console.log(this.productName, typeof this.productName)
        console.log(this.amount, typeof this.amount)
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <input type="text" id="productName" name="productName" :value="productName">
  <input type="hidden" id="amount" name="amount" :value="amount">
  <button @click="submitForm">Submit</button>
</div>

You can see the return data type in the console on click of submit.

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