2

I have created an input form in HTML with a combination of input and select boxes. I would like to populate a select menu on the fly with data from the input boxes - for example:

Employee One: Jim Employee Two: John Employee Three: Bob

This would then populate a select menu with the Jim, John and Bob as options.

I am trying to avoid having to submit the input data first as I would really like to have all the input on one page. I submit all the data to a MySQL database, so worst case I could submit it in sections and read it back, but would appreciate any suggestions for doing it on the fly.

Thanks for any help.

Blair

1

1 Answer 1

0

Maybe something like this?

HTML:

<input id="employee_name" type="text" placeholder="Type here the Employee name"/>
<input id="add_employee" type="button" value="add"/>

<select id="employee_list">
</select>

Jquery:

$('#add_employee').click(addEmployee);

function addEmployee(){
    var employee_name = $('#employee_name').val();
    $('#employee_list').append('<option  value='+employee_name+'>'+employee_name+'</option>');
}
Sign up to request clarification or add additional context in comments.

2 Comments

That works - I was trying to do it without any button clicks, but I think that is impossible. Happy with this as I don't have to submit the form.
Good to know that it helped you :)

Your Answer

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