0

I m not a so good in coding.. I want to add a form with 3 buttons with different actions..I got a code but it is not working for me..

<script type="text/javascript">
    function OnSubmitForm() {
        if(document.myform.operation[0] .checked == true) {
            document.myform.action = "/site_109.xhtml";
        } else if (document.myform.operation[1] .checked == true) {
            document.myform.action = "/site_110.xhtml";
        } else (document.myform.operation[2] .checked == true) {
            document.myform.action = "/site_111.xhtml";
        }
        return true;
    }
</script>
<form id="myform" name="myform" onsubmit="return OnSubmitForm ();">
    <strong><font color='oil'>Enter number:</font></strong><br>
    <input maxlength='10' name='get-no' placeholder='Mobile Number' type='text'><br>
    <strong><font color='oil'>Enter Message:</font></strong><br>
    <input name='msg' placeholder='Message' type='text'><br>
    <input checked name="operation" type="radio" value="1">Call
    <input type="radio" name="operation" value="2">Sms
    <input type="radio" name="operation" value="2">Save
    <p><input name="submit" type="submit" value="save"></p>
</form>

I want it to show result "Details saved successfully" on the same page after submission. Plz give me the corrected code.thank you.

tanaydin
  • 5,171
  • 28
  • 45

1 Answers1

0

I have seen versions of this question in many places. I too wanted more than one button. The method that works for me is to add a hidden field and have the onclick attribute set a value. That hidden field will have the value which represents the action I wish to perform.

<input id="desired-action" name="action" type="hidden" value="" >
<button class="submit-button" type="submit" onclick="set_form_value( 'desired-action', 'new');" >New</button>
<button class="submit-button" type="submit" onclick="set_form_value( 'desired-action', 'update');" >Update</button>

<script>
function set_form_value( idField, value )
{
    document.getElementById( idField ).value = value;
}
</script>
David B
  • 1
  • 1