0
How do I leave selected one option
via jquery? I know it’s because of your attribute selected
, but I have no idea how to do this.
The following code to illustrate how I was doing:
Session
var sessao = localStorage.getItem('selected');
var nomeSessao = localStorage.getItem('selectedName');
if((sessao*1) >0)
{
$('.optSelecionado').text(nomeSessao);
}
Option listing
function mapa()
{ $.unblockUI();
var identificador = localStorage.getItem('identificador');
var sessao = localStorage.getItem('selected');
var nomeSessao = localStorage.getItem('selectedName');
$('.optSelecionado').text(nomeSessao);
var url = urlprojeto+"/dispositivo/service/enterprise/apps/mapa.php";
var www = "device="+identificador+"";
var www = get_contents(url,www);
var wwwD = www.dados;
var wwwLen = wwwD.length;
var ts = '<select id="caminho" style="width: 100%;">';
ts+= '<option class="optSelecionado" value=""></option>';
for( s=0; s<wwwLen; s++ )
{
var referencia = wwwD[s].erp_obr_ass_codigo;
var nome = wwwD[s].erp_obr_ass_nome;
var identacao = wwwD[s].identacao;
ts+= '<option value="'+referencia+'" name="'+identacao+'">'+identacao+'</option>';
}
ts+='</select>';
$(".mapa").html(ts);
}
But using the text
he duplicates my option, would like to leave a option
with nothing, I tried using the function remove()
to withdraw the class optSelecionado
, but as I said I’d like to have a option
blank
Will leave it selected by value or text ? what would be the condition to mark it as Selected?
– Gabriel Rodrigues
would be the following situation, I have a "session" if it is in this session (which is made by the value of the option itself) I would like it even to come with the value of this session.
– Marcos Henrique
Post some code that exemplifies this please.
– Gabriel Rodrigues
edited the question of a look
– Marcos Henrique
I posted a solution before you edit the question, now with your edition I understand even less what you want, you want to leave the input empty with the class
optSelecionado
selected?– Felipe Assunção
@Felipeasunción your solution suits me
– Marcos Henrique
I just tried to exemplify what I want to do, but it’s something simple, that with the
.prop()
answer me– Marcos Henrique