0

I am trying to make a Form in which there are two Submit buttons. Here is the form.

<form method="POST" id="addCreditsForm">
    <div class="row">
        <div class="col s12 m10 offset-m1 l10 offset-l1 input-field">
            <input type="number" name="amount" id="amount" required/>
            <label for="amount">Amount</label>
        </div>
        <div class="col s12">
            <p id="addWithPaypal" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Paypal</p>
            <p id="addWithInstamojo" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Instamojo</p>
        </div>
    </div>
</form>

I am trying to do this with JQuery. Here is the JQuery Code.

$(document).ready(function(){
    $("#addWithPaypal").click(function(){
        $("#addCreditsForm").attr('action'."paypal/add/credits");
        $("#addCreditsForm").submit();
    });

    $("#addWithInstamojo").click(function(){
        $("#addCreditsForm").attr('action'."instamojo/add/credits");
        $("#addCreditsForm").submit();
    });
});

But When I click on any of the elements responsible for calling JQuery functions on Event, JQuery is not working. I tried to fire Alert on click event of both the buttons but it's not working too!

I have no Idea what's wrong. Please Help me out!

1 Answer 1

1

Typo instead of , you kept . in

`$("#addCreditsForm").attr('action',"instamojo/add/credits");`
                                       ^here  

$("#addCreditsForm").attr('action',"paypal/add/credits");

$(document).ready(function(){
    $("#addWithPaypal").click(function(){
        $("#addCreditsForm").attr('action',"paypal/add/credits");
        $("#addCreditsForm").submit();
    });

    $("#addWithInstamojo").click(function(){
        $("#addCreditsForm").attr('action',"instamojo/add/credits");
        $("#addCreditsForm").submit();
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form method="POST" id="addCreditsForm">
    <div class="row">
        <div class="col s12 m10 offset-m1 l10 offset-l1 input-field">
            <input type="number" name="amount" id="amount" required/>
            <label for="amount">Amount</label>
        </div>
        <div class="col s12">
            <p id="addWithPaypal" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Paypal</p>
            <p id="addWithInstamojo" style="margin-top:5px;margin-bottom:5px;" class="btn blue">Pay with Instamojo</p>
        </div>
    </div>
</form>

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, That's the solution! How can I be so dumb, Lol!
You can accept the answer if it helped you @AdarshSojitra

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.