0

I have a salary adding form, where I have to manually type in the rate for the morning and night shifts for every company. Every company have different rates. I want to make it as when the company's name is chosen, the rates should be retrieved from the database using php and fill in automatically so that the user only has to input how many days the labourer has worked. I'm not sure of how to implement this. Every company's rates are stored in a database. How to do the jquery to make this idea work?

    <input type="text" name="name">  
     <div>
     <label>Morning Shift Rate: </label>
     <input type="number" name="morning_rate" 
     id="morning_rate">  

     <label> Days : </label>
     <input type="number" name="morning_day" id="morning_day">  
     </div>
                 
    <div>
    <label>Night Shift Rate: </label>
    <input type="number" name="night_rate" id="night_rate">  
                   
    <label> Day : </label>   
    <input type="number" name="night_day" id="night_day" >  
    </div>

  <script>
        $(document).ready(function(){
           $('#name').click(function(){
            ????

           })        
    })
          </script>    

1 Answer 1

0

You must used AJAX call to request the datas from database. But, you must have too a backend language (ex: PHP, Python...) because it's him who will retrieve the datas from database. Example with jQuery:

submitForm = function(url, element) {
    const dataForm = element.serializeArray();
    let data = {'id': dataForm[0]}

    $.ajax({
        method:'POST',
        url: url, // Your url to send the datas (the id in your view for example) at your backend
        data: data,
    }).then(response () {
        console.log(response.rate)
    })
}

I hope so help you.

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

2 Comments

Thanks. But could you give me an example of how to do it with PHP?
Yes, you have already a response in this website : stackoverflow.com/questions/39341901/…

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.