Jump to content
PF2G

Receber valor de Select Option

Recommended Posts

PF2G

Bom dia,

Como faço para receber o value da opção selecionada em #layout_select e actualizar no <p>?

<!-- HEAD -->
<script>
$(document).ready(function() {
var optarray = $("#layout_select").children('option').map(function() {
return {
"value": this.value,
"option": "<option value='" + this.value + "'>" + this.text + "</option>"
}
})
$("#column_select").change(function() {
$("#layout_select").children('option').remove();
var addoptarr = [];
for (i = 0; i < optarray.length; i++) {
if (optarray[i].value.indexOf($(this).val()) > -1) {
addoptarr.push(optarray[i].option);
}
}
$("#layout_select").html(addoptarr.join(''));
}).change();
var myString = $("#layout_select").val();
var myArray = myString.split('_');
$("p#val").text(myArray[1]);
});
</script>

<!-- BODY -->
<select name="column_select" id="column_select">
<option value="col1">Com partida em</option>
<option value="col2">Albufeira</option>
<option value="col3">Braga</option>
<option value="col4">Lisboa</option>
<option value="col5">Porto</option>
<option value="col6">Vigo</option>
</select>
<br/><br/>
<select name="layout_select" id="layout_select" >
<!--Below shows when '1 column' is selected is hidden otherwise-->
<option value="col1_none">Com destino em</option>
<!--Below shows when '2 column' is selected is hidden otherwise-->
<option value="col2_none">Com destino em</option>
<option value="col2_braga">Braga</option>
<option value="col2_lisboa">Lisboa</option>
<option value="col2_porto">Porto</option>
<option value="col2_vigo">Vigo</option>
<!--Below shows when '3 column' is selected is hidden otherwise-->
<option value="col3_none">Com destino em</option>
<option value="col3_albufeira">Albufeira</option>
<option value="col3_lisboa">Lisboa</option>
<option value="col3_porto">Porto</option>
<option value="col3_vigo">Vigo</option>
<!--Below shows when '4 column' is selected is hidden otherwise-->
<option value="col4_none">Com destino em</option>
<option value="col4_albufeira">Albufeira</option>
<option value="col4_braga">Braga</option>
<option value="col4_porto">Porto</option>
<option value="col4_vigo">Vigo</option>
<!--Below shows when '5 column' is selected is hidden otherwise-->
<option value="col5_none">Com destino em</option>
<option value="col5_albufeira">Albufeira</option>
<option value="col5_braga">Braga</option>
<option value="col5_lisboa">Lisboa</option>
<option value="col5_vigo">Vigo</option>
<!--Below shows when '6 column' is selected is hidden otherwise-->
<option value="col6_none">Com destino em</option>
<option value="col6_albufeira">Albufeira</option>
<option value="col6_braga">Braga</option>
<option value="col6_lisboa">Lisboa</option>
<option value="col6_porto">Porto</option>
</select>
<p id="val"></p>

Obrigado,

PF2G

Share this post


Link to post
Share on other sites
NunoDinis
document.getElementById('val').innerHTML = 'Valor da combo';


Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.

ndsotware.org

Share this post


Link to post
Share on other sites
PF2G

document.getElementById('val').innerHTML = 'Valor da combo';

Mas como faço para o texto mudar sempre que selecciono outra opção no $("layout_select")?

Share this post


Link to post
Share on other sites
NunoDinis

colocas a função no evento onchange do select.

<select id="blablabla" onchange="funcao()">
<!-- // -->


Estranha forma de vida que tem a capacidade de transformar comandos em mensagens de erro.

ndsotware.org

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.