是否可以在我的表单提交按钮上使用onClick功能?

I store multiple data in a table for enquiry basis.. which is successfully stored in my table. but now i also want to store those same data in Booking basis.

So i used onClick function for storing enquiry data. and now i want to store booking data in table from form submit button.

here is my form submit button code:

<button type="submit" class="booking-btn" onclick="btn_booking_hour();" id="btn_booking_hour">Book Now</button>

Here is my form action:

<?php echo form_open('booking/'.$product->id); ?>

And here my function:

function btn_booking_hour()
    { 

    var date = $('#datehour').val();
    var renter_id = $("#ownerid").val();
    var guests_quantity = $('#no_of_guests').val();
    var property_id = $('#property_id').val(); 
    var selectedIds="";
    var selectedObject = document.getElementsByClassName('hour_slots_available slot_activated');
    for(var i=0;i<selectedObject.length;i++)
      selectedIds+=selectedObject[i].id+",";

    if(selectedIds == ""){

        alert("Please select Hour-Slot(s) before Booking");
    }
    else{

        $.ajax({

    type: 'POST',
    dataType:'json',
    url:baseURL+'site/rentals/ajaxhourshow',

    data:{'selectedHours':selectedIds,'property_id':property_id,'date':date,'guests_quantity':guests_quantity,'renter_id':renter_id},

    success: function(responce){

        var myJSON = JSON.stringify(responce);
        var packet = $.parseJSON(myJSON);

        var  prd_id=packet.property_id;
        var hour_slots=packet.hour_slots;
        window.location.href = baseURL+'booking/'+prd_id;
        }
    });
   }

}

Please suggest me how can i submit a form with data within their onClick function. Thanks..

Not sure if you are using a form, if you are using it you can can use onsubmit handler and return the action. In that case you wont need onclick handler in the button

<form onsubmit = "return btn_booking_hour()">
  // Rest of code
</form>

You can also do like this

$('#form').on('submit',function(e){
 e.preventDefault();
 // rest of the code
})

you can use this code

 function btn_booking_hour(){
// your other code
 document.getElementById('formid').submit();
// formid = form id
 }

or also use jquery

function btn_booking_hour(){
// your other code
 $('#formid').submit();
// formid = form id
 }

i got your point so you can also use it

$(function() {
//hang on event of form with id=myform
$("#myform").submit(function(e) {

    //prevent Default functionality
    e.preventDefault();

    rest of your code

});

});