Good morning I am trying to capture the value of a select
that is outside of a form to send it to a BD, with an example that I was given on this site I managed to send 3 parameters but the select
always sends the first item and not the one I select then try to send what I select to input
text but send it to me empty, this is the code with which I capture the select
in a input
.
<script type="text/javascript">
function selecOp()
{
var op=document.getElementById("no_conformidad");
var tt=document.getElementById("text");
if (op.selectedIndex==0)tt.value="";
if (op.selectedIndex==1)tt.value="MESA-1";
if (op.selectedIndex==2)tt.value="MESA-2";
if (op.selectedIndex==3)tt.value="MESA-3";
if (op.selectedIndex==4)tt.value="MESA-4";
if (op.selectedIndex==5)tt.value="MESA-5";
if (op.selectedIndex==6)tt.value="MESA-6";
}
var mesa=document.getElementById("text");
</script>
<select name="no_conformidad" id="no_conformidad" onchange="selecOp()">
<option>Selecciona una mesa</option>
<option>MESA-1</option>
<option>MESA-2</option>
<option>MESA-3</option>
<option>MESA-4</option>
<option>MESA-5</option>
<option>MESA-6</option></select>
<input type="text" name="text" id="text" size="4">
and with this I sent it by ajax
<script>
<script>
$(document).on('ready',function(){
//var mesa=document.getElementById("text").value;
mesa = document.getElementById("text").value//obtener valor del
input
var item = $('#it1').val();
var precio = $('#it2').val();
$('#boton1').click(function(){
var url = "enviar.php";
$.ajax({
type: "POST",
url: url,
data:{mesa:mesa,item:item,precio:precio},
success: function(data)
{
// $('#resp').html(data);
}
});
alert(mesa);
return false;
});
});
</script>