Skip to content
Advertisement

select option to fetch other inputs

What Im trying to do is select item name where is ID and if item selected it automatically adds that item serial number to serial number input.

I think it should be used ajax maybe but I dont know how exactly.

JavaScript

I have also other inputs like description, price and etc.. to fetch these inputs with these values.

example: i need get data to my field from select option id (value)

JavaScript

Advertisement

Answer

That value is already shown inside your select-box you can simply use onchange event and then use $(this).find("option:selected").text().split('-')[1] this will give serial no then put it inside your input-box using $('[name=item-serialnumber]').val(somevalue) .Also ,you can send id via ajax to your server page and fetch result.

Demo Code :

JavaScript
JavaScript

Then , at your server end get the id pass via ajax using $_POST['id'] then fetch result using select query and send them back to ajax using echo json_encode($somearray); i.e:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement