Skip to content
Advertisement

Select option only posts id, I need the value too

I have an issue in a simple PHP MySQL project. When I try to fetch a record from a select option, it only gives me the id. I want the value from the select to be passed too.

JavaScript

This is the update function code:

JavaScript

Advertisement

Answer

You can post your province name instead of the id this way:

JavaScript

Your $_POST['province_id'] will then contain the province value instead of the current id.

A way to pass along both the id and the value (in case you need to retain the id for some additional processing) through your option would be this:

JavaScript

Then after the submit, you’d simply split the two by the ‘|’ delimiter.

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