I hope you can help me with the following... I have 3 files, 1 html, 1 php and 1 js
Inside the html is the following:
<div class="seccion1">
<h3>Modelo</h3>
<select id="modelo" name="modelo">
<option value=""></option>
<option value="40">40</option>
<option value="60">60</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
</select>
</div>
<div class="seccion4">
<ul class="actions">
<li><input type="button" id="generar" value="Genenerar plantilla" class="special" onclick="generarP()" style="border-radius: 5px;" /></li>
</ul>
<textarea id="Output" readonly="true"></textarea>
</div>
In the php I have this:
<?php
if(isset($_POST['action'])) {
$action = $_POST['action'];
switch($action) {
case 'ejemplo' : ejemplo();break;
case 'generar' : generarP();break;
}
}
function generarP() {
$modelo= $_POST['modelo'];
return $modelo;
}
}
?>
and in the js this:
function generarP() {
const mod = document.getElementById("modelo");
//Ningun servicio
if (mod.value == "") {
alert("Selecciona un modelo");
} else
$.ajax({
url: 'https://dominio/php/archivo.php',
data: {action: 'generar', modelo: this.title },
type: 'post',
success: function(output) {
document.getElementById("Output").innerHTML = (output);
}
});
}
However, I can't get the value to be displayed, in practice I'm going to use the model for the php code and then I'll print the result in the "output" textarea :,(
I already found the error, I missed putting the
.value
So the js is as follows: