SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    HTML Code:
       
       <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?

  2. #2
    SitePoint Guru Ruben K.'s Avatar
    Join Date
    Jun 2005
    Location
    Alkmaar, The Netherlands
    Posts
    693
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Rename that input and it will work

  3. #3
    SitePoint Evangelist
    Join Date
    Apr 2005
    Location
    London, UK
    Posts
    505
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Define a function and call in onsubmit attribute of the form.
    HTML Code:
    <form name="form" method="post" id="form1" class="competition" action="url" onsubmit="return frmFunction(this);">
    And define the function in javascript:
    Code 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.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •