Submit form with js

Hi Guys,

Tried reserching this in google, but had not much joy. I am trying to us JavaScript to join two input fields together then submit the form.

here is my form



   
   <form name="form" method="post" id="form1" class="competition" action="url">
   
   <label for="accNum">F Name</label><br />
   <input type="text" name="fname" /><br />
   
      <label for="accNum">Account Number</label><br />
	     
	     <input type="hidden" name="AccNum_DATATYPE" value="text" /><input type="text" name="AccNum" value="" maxlength="2" id="accNum" class="req-string" style="width: 15px;" />
         
	     <input type="hidden" name="AccNum_DATATYPE" value="text" /><input type="text" name="AccNum" value="" maxlength="2" id="accNum" class="req-string" style="width: 15px;" /><br />
  
       <input name="" id="submit" type="image" src="" class="submit" onClick="f_validateForm();return false;" />
   </div>
	 
   </form>
  

it’s only the AccNum fields which are individual fields in the form which need to produce a joint string which can then be posted with the form. any ideas on how i can get this working please?

If you’ve tried form.submit() and it’s not working, it’s because you have an input with ID ‘submit’, which disallows the submitting of the form with javascript :slight_smile:

Rename that input and it will work :wink:

thanks for the input Ruben, but thats not really what i asked for. I wanted to know if there was a way to format the posted fields with js before it is submited to the url. I have 3 fields in my form that i wanted to join as one field then submit that field alonf with the post.

cheers

Define a function and call in onsubmit attribute of the form.


<form name="form" method="post" id="form1" class="competition" action="url" onsubmit="return frmFunction(this);">

And define the function in javascript:


function frmFunction(frm){
    frm.txtFieldname.value = frm.field1.value + ' ' + frm.field2.value + ' ' + frm.field3.value;
    return true;
}

The function above will store the value from three fields in the form to another field of the form named ‘txtFieldname’.

Hope this will help you.