发布下拉列表的文本而不是PHP中的值
I have this code of a Select in html but i want to send by POST the text.. not the values.. any ideas?? However I do still require the values as well. Thanks in advance!
<select name="calificaciones" id="calificaciones">
<option selected value="0"> Elige una opción </option>
<option value="1">Demoró en terminar</option>
<option value="1">Impuntual</option>
<option value="2">Grosero(a) en su trato</option>
<option value="2">Sucio (a) en su trabajo</option>
<option value="4">Dejó inconcluso el trabajo</option>
<option value="4">No respetó el precio acordado</option>
<option value="8">Fue deshonesto (a)</option>
<option value="8">Robó</option>
</select>
Use jQuery. Have a look http://jsfiddle.net/whizzzkid/HsKEd/2/
<select name="calificaciones" id="calificaciones">
<option selected value="0"> Elige una opción </option>
<option value="1">Demoró en terminar</option>
<option value="1">Impuntual</option>
<option value="2">Grosero(a) en su trato</option>
<option value="2">Sucio (a) en su trabajo</option>
<option value="4">Dejó inconcluso el trabajo</option>
<option value="4">No respetó el precio acordado</option>
<option value="8">Fue deshonesto (a)</option>
<option value="8">Robó</option>
</select>
<div id="output"></div>
As simple as .html() refer to the fiddle
/*$('option').each(function(){
$('#output').append($(this).html() + '<br>');
console.log($(this).html());
});*/
$('select').bind('change', function(){
$('#output').html($(this).find(':selected').html() + '<br>');
console.log($(this).find(':selected').html());
});
So you can submit the form by jquery after you have their html values. ALSO DO NOT FORGET TO CHECK YOUR BROWSER'S CONSOLE.
edit 1: even a better code.
the only solution using php is to substitute the html value attributes. If you want to keep numeric value on that attribute, the only solution is using jquery to build a post request which grab the text instead of the numeric value on submit.
I think you can use
var calificaciones = this.options[this.selectedIndex].value +':' + this.options[this.selectedIndex].innerHTML;
So, if you send calificaciones
then you can explode it (you already have the idea) into an array using :
on the server side. If you use POST
then it should be simply
$calificaciones = isset($_POST['calificaciones']) ? explode(':', $_POST['calificaciones']) : null;