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

152
Views
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 answers
Answer question

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 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!