2

i have two submit buttons in my form one is SUBMIT and another one is SCHEDULE NEXT ROUND..when user click on submit the form values should store in database and redirect to view page..and when user click on schedule next round the values should stored in database and again form will be stay there and user can add details in form..

here is my Submit buttons:

<button type="submit"  name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>

here is my another button:

<button type="submit" name="submit" class="btn btn-primary" value="schedule">Schedule Next Round</button><br></br> 

Can anyone help me..

Thanks in advance..

4
  • Please show us the JS code you've written so far. Commented Feb 27, 2017 at 11:40
  • i didn't write any js code yet? Commented Feb 27, 2017 at 11:44
  • i just tried like this in my controller if($this->input->post('submit')=="submit") { $this->CandidateModel->add_candidate_selection($this->input->post()); redirect(base_url('Candidate/view_candidate_selection')); } Commented Feb 27, 2017 at 11:44
  • I honestly suggest you to do some reading on Ajax requests. But still this links should help too => stackoverflow.com/questions/5004233/… , stackoverflow.com/questions/4210025/… Commented Feb 27, 2017 at 11:48

2 Answers 2

1

Get the button click by its button name and post value to required page using following method:

$(document).ready(function(){
$("input[name=Button1]").click(function(){
alert("Button1 clicked");
$.post('ajax/test.html', function(data) { 

});

});
$("input[name=Button2]").click(function(){
alert("Button2 Clicked");
$.post('ajax/test.html', function(data) { 

});

});
})
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></head>
<body>
<form method="post">
<input type="submit" name="Button1" value="Button1">
<input type="submit" name="Button2" value="Button2">
</form
</body>
</html>

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

2 Comments

$.post('ajax/test.html', function(data) what is the purpose of this line.can you please explain..
Using this line you can submit value to other page...that is pass post values to test.html page to process and store database.
0

Use different function for submit and Schedule Next Round.For Sumbit use from submit and for Schedule Next Round use different function.

<button type="submit"  name="submit" value="submit" class="btn btn-primary" value="submit">Submit</button>

        <button type="button" name="submit" class="btn btn-primary" value="schedule" onclick="ScheduleNextRound();">Schedule Next Round</button><br></br>
    function ScheduleNextRound() {
$.ajax({
            type: 'POST',
            data: YourDataYouWantToSendAsObject,
            url: YoutServerSideUrl,
            async: false,
            success: function (value) {
                returnData = value //as you don't want to refresh
            },
            error: function (jqXHR, textStatus, errorThrown) {
                genericError(jqXHR, textStatus, errorThrown);
            },

        });
}

1 Comment

something like {'name':'abcd','age':'27'} etc and if you don't want to send anything just send {} empty object