Populating DIV after selecting a die from the list

0

Can anyone help me with this code? I assume that I do not understand about 80%, I am trying to pop the INFO div after selecting one of the options in the SELECT field, this information will be relative to the selected option, the information regarding the selected option is contained in the example.php page ... The way that is, it is working, but the information is being presented within an OPTION, I would at least want it to be populated within an INPUT

<html>
 <head>
<title>Exemplo</title>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<label for="montadora">Montadora:</label>
<select name="montadora" id="montadora">
<option value="1">Fiat</option>
<option value="2">Ford</option>
<option value="3">Volkswagen</option>
</select>
<br />
<label for="veiculo">Veiculo:</label>
<select name="veiculo" id="veiculo"></select>    

<div id="INFO">      
</div>      

<script type="text/javascript">      
$(document).ready(function(){
$("#montadora").change(function(){
$.ajax({
type: "POST",
url: "exemplo.php",
data: {montadora: $("#montadora").val()},
dataType: "json",
success: function(json){
var options = "";
$.each(json, function(name, value){
options += '<option value="' + name + '">' + name + '</option>';
});
$("#veiculo").html(options);
}
});
});
});

</script>
</body>
</html>
    
asked by anonymous 30.05.2014 / 05:06

1 answer

1

Realize the line

options += '<option value="' + name + '">' + name + '</option>';

It is responsible for creating the values inside the tag option, to change just change the line to the desired tag. In the case of input of type texto would look something like.

options += '<input type="text" value="' + name + '"/>';

To remove input and display the text cleanly just remove the tags and leave only the name variable.

Also check that data is included within select with id veiculos . To change to the div with id info you must change the line

$("#veiculo").html(options);  

To

$("#info").html(options);
    
30.05.2014 / 05:17