I need to change some values in a pre-set options box using JQuery
, an example of code
:
<div id="div-archive-max-size">
Max size for archive :
<select name="archive-max-size">
<option value="10485760">10240 Mo</option>
<option value="5242880">5120 Mo</option>
<option value="4194304">4096 Mo</option>
<option value="3145728">3072 Mo</option>
<option value="2097152">2048 Mo</option>
<option value="1048576">1024 Mo</option>
<option value="524288">512 Mo</option>
<option value="262144">256 Mo</option>
<option value="204800">200 Mo</option>
<option value="102400">100 Mo</option>
</select>
</div>
The idea is to change the numerical value ( value="10485760"
) plus the description ( 10240 Mo
) to ( value="17485760"
) and ( 17 Gb
) respectively, and so on with the others ... with custom values and descriptions . It would be a script
to use in'Tampermonkey' or similar ..
Someone could give me an answer but honestly I do not know how I can apply the solution, the one they knew how to give me:
You only have to go through each
option
ofselect
with the method.each()
. To assign the value tooption
, use the function.val()
and to assign the text.text()
.For example:
function modificar()
{
var data = [{val: "15485760", text: "15 GB"},{val: "otros valores", text: "otros valores"},{val: "otros valores", text: "otros valores 2"}];
$("select[name='archive-max-size'] option").each(function(index, element){
$(element).val(data[index].val)
.text(data[index].text);
});
}
Thank you very much already.