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..

  • Please show us the JS code you've written so far. – Nir Tzezana Feb 27 '17 at 11:40
  • i didn't write any js code yet? –  Feb 27 '17 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')); } –  Feb 27 '17 at 11:44
  • I honestly suggest you to do some reading on Ajax requests. But still this links should help too => http://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php , http://stackoverflow.com/questions/4210025/pass-data-from-jquery-to-php-for-an-ajax-post – mane Feb 27 '17 at 11:48

2 Answers2

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>
thangavel .R
  • 466
  • 4
  • 13
  • $.post('ajax/test.html', function(data) what is the purpose of this line.can you please explain.. –  Feb 28 '17 at 05:32
  • Using this line you can submit value to other page...that is pass post values to test.html page to process and store database. – thangavel .R Feb 28 '17 at 05:50
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);
            },

        });
}
ANIK ISLAM SHOJIB
  • 3,002
  • 1
  • 27
  • 36