Ross Symonds
Ross Symonds

Reputation: 710

How can I manipulate the values on a form when the submit button is clicked

Update 2 - Solved

On reflection with Update 1 I was close to solving my problem, this is my final solution.

<button type='submit' onclick="validate()" class='btn btn-default'>Submit</button>


validate = function() {
       document.getElementById('id_Price').value="2988.99"
}

Update 1

I have had a bit more success with this -

<button type='submit' onclick="validate()" class='btn btn-default'>Submit</button>


validate = function() {
  console.log("Anything happening? (2)")

  RoomBookingsForm['Price'].value()="2988.99"
  document.getElementById('id_Price').value()="2988.99"
}
      

Original Question

How can I manipaluate the values on a form when the submit button is clicked? I have tried -

<button type='submit' class='btn btn-default'>Submit</button>
function submit(){
  document.getElementById('id_Price').innerHTML()="2988.99"
  RoomBookingsForm['Price'].value()="2988.99"
  document.getElementById('id_Price').value()="2988.99"
}


<button type='submit' onsubmit='submitForm()' class='btn btn-default'>Submit</button>          
function submitForm(){
  document.getElementById('id_Price').innerHTML()="2988.99"
  RoomBookingsForm['Price'].value()="2988.99"
  document.getElementById('id_Price').value()="2988.99"
}

The purpose of this is to present the dates on the form based on the users language / timezone web browser settings. But ultimately save the date to the backend using the American format.

Upvotes: 0

Views: 591

Answers (1)

A. Meshu
A. Meshu

Reputation: 4148

In order to change the value when user hits submit you can (for example) change the type to button and then submit your data programaticaly via js.

Something like this:

validate = function() {
  // change value when click
  document.getElementById('id_Price').value="2988.99";
  // submit the form progrematically 
  document.getElementById('demo').submit();
}
<form id="demo">
  <input id="id_Price" value="100" />
  <button type='button' onclick="validate()" class='btn btn-default'>Submit</button>
</form>

Upvotes: 1

Related Questions