Pages

Saturday 14 April 2012

Form Submission Using JavaScript


<portlet:actionURL var="formDetailsUrl">
           <portlet aram name="customParam" value="nothing"/>
</portlet:actionURL>


<form name="detailForm" method="post" onsubmit="callFormDetails()">
   <select id="topic" name="topic" >
     <option ${topic=='1' ? 'selected' : ''} value="1">ONE   </option>
      <option ${topic=='2' ? 'selected' : ''} value="2">TWO    </option>
                          
</select> 
  <input type="submit" value="submit">
</form>   




<script type="text/javascript">
           function callFormDetails (contID)
           {
                var submitURL ='${formDetailsUrl}';
                var topic     = document.getElementById("topic");
                submitURL     = submitURL.replace("nothing",topic);
                document.detailForm.action=submitURL;
                document.detailForm.submit();
           }
</script>


NOTE : In the javascript we can change the parameter for the URl we define. As this helps us in having control in sending dynamic parameters directly in the URl

7 comments:

  1. the submit is not working in my scenario do you have suggestions are know any reasons why it is not working?!!

    ReplyDelete
  2. Same the Submit not working in my case as well, do you find any solution for this?

    ReplyDelete
  3. Can you please ,let me check your code pls.
    Also please note that there was a small spelling mistake at
    ,
    Its param not aram.

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  4. Thanks Srikath for helping me, What am trying to achive is one checkbox selection submit a form ,below is


    JavaScript:

    function myFormSubmit() {

    var submitURL ='${actionUrl1}';


    document.myForm.action=submitURL;
    document.myForm.submit();


    }

    For some reason rest of html tag unable to post in Blog, but I have defined actionUrl1 and MyForm is the form, If you want I can email to you at subinjacob@gmail.com, The stuck at document.myForm.submit() as null

    Thanks

    -Subin

    ReplyDelete
  5. Please mail your code to srikanthreddy1410@gmail.com.I will check and update you !

    ReplyDelete
  6. Hi Srikanth, Have you got chance to check code that I emailed to you?

    ReplyDelete