I already have this :
With jQuery:
$("#ListSujet option").each(function(){
$(this).val($(this).val().replace(",True", ""));
}
$.each($("select").find("option"), function() {
var splitVal = $(this).val().split(",")
$(this).val(splitVal[0])
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>
Try this:
$("#ListSujet option").each(function(){
$(this).val($(this).val().split(",")[0]);
//console.log($(this).val());
});
$("#ListSujet").on("change",function(){
console.log($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>
You can use callback function of .attr()
to modify existing value:
$('#ListSujet option').attr('value',function(i,o){
return o.substring(0, o.indexOf(','))
});
Working Snippet:
$('#ListSujet option').attr('value',function(i,o){
return o.substring(0, o.indexOf(','))
});
$("#ListSujet").on("change",function(){
console.log($(this).val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<select id="ListSujet" name="ListSujet">
<option value="514402,True">Copie de Musculation</option>
<option value="514430,True">Gecko Leopard</option>
</select>