Jump to content

Change input value on submit


Guest jimi_jax

Recommended Posts

Guest jimi_jax

I am relativley new to javascript...I have a form with (for simplicity sake) two input fields. I want to hide one and change the value of the second when the user clicks on the submit button. I know how to hide an input field but how can I change the value when the submit button has been pressed

Link to comment
Share on other sites

HTML

<form><input type="text" id="box1" size="20"/><input type="text" id="box2" size="20"/><input type="button" id="submitButton" value="Submit" onclick="submitForm()">/></form>

JS

<script type="text/javascript">  function submitForm()  {    var box1 = document.getElementById('box1');    var box2 = document.getElementById('box2');    //hide box1    box1.style.display = 'none';    //change value of box2    box2.value = "some value";    document.forms[0].submit();  }</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...