6
I know almost nothing about Javascript but I managed to use Chosen to change my selects. What I’m not getting is to use the Trigger that the site indicates to update the field.
I want each time you click on the select field and the dropdown list action, update the values.
I know the website says to put $("#form_field").trigger("chosen:updated");
but I don’t know where, I don’t know what the #form_field
. Is the form id? Field? Do I have to create an event with onselect
or onclick
?
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="chosen/chosen.css">
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="chosen/chosen.jquery.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
<title>Cadastro de Filmes</title>
</head>
<script type="text/javascript">
$(function(){
$('.chzn-select').chosen({width: "50%", no_results_text: "Sem registro de ", size: "5"});
});
</script>
<body>
<div class='cadastro' >
<h1>Cadastro de Filmes</h1>
<form action='' method='post' enctype='multipart/form-data' name='form1' id='form1'>
<p>País
<select name='pais[]' data-placeholder=' ' multiple class='chzn-select')
<?php
//LAÇO PARA BUSCAR TODOS OS DADOS DO BANCO MARCANDO AQUELES QUE ESTÃO SELECIONADOS
$j=0;
$tam=sizeof($pais_sel);
for($i=0;$i<sizeof($pais);$i++){
if($pais[$i]==$pais_sel[$j]){
echo "<option value='$pais[$i]' selected>$pais[$i]</option>";
if($j<$tam-1){
$j++;
}
}else{
echo "<option value='$pais[$i]'>$pais[$i]</option>";
}
}
?>
</select>
</p>
<p>
<input name='enviar' type='submit' id='enviar' value='Enviar' />
</p>
</form>
</div>
</body>
</html>
You can put the code you have here?
– Sergio
How do I put code here?
– adairbsjr
You can [Edit] the question and put the code in the question. If you need help formatting the code we help.
– Sergio
I put the code in, but it didn’t all show up.
– adairbsjr
Hello, fellas. I’ll try to be clearer. I have a film registration form in which you have a country field, for example, to select the countries that co-produced that film. I will create next to this field a new button to register new countries. What I need is for the country field of the first form to update with the new country that I just registered without having to refresh the page, because then I would lose the data typed in the other fields. I think it’s with the update function of Chosen that I’m using, but I don’t know how to use it right. .
– adairbsjr
There are mistakes here
<select name='pais[]' data-placeholder=' ' multiple class='chzn-select');" >
has);"
the more. There is some error in the console?– Sergio
Hello, Sergio. I’ve noticed the error, it was typing, but the problem is not in this code. I want to know what I have to add to it to update the select tag with Chosen. Hugs
– adairbsjr
It would be ideal to make a jsFiddle with the problem. But I’ll take a look. If you can however put the rendered HTML, better to test.
– Sergio
Hello, Sergio. Sorry, I don’t know how to use jsFiddle. Want to put screenshots of the page?
– adairbsjr
Can you explain what’s missing here: http://jsfiddle.net/rq7fkzpk/
– Sergio
You managed to solve this problem?
– Sergio