Passer du javascript au Jquery
Bonjour,
J'ai un code javascript qui me permet de remplir une liste d�roulante via une popup. Pour cela j'utilise du Javascript mais j'aimerais passer en Jquery.
Voici le code de la page principale:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
function doc(id_op) {
if (document.layers) { // NS 4 et <
return document[id_op];
}
if (document.all) { // IE
return document.all[id_op];
}
if (document.getElementById) {
return document.getElementById(id_op);
}
}
function ajout(id_op, value, text) {
formulaire = doc(id_op);
// Recuperation des informations
nb = formulaire.length;
// On compte le nombre d'<option />
nouvel_element = new Option(text, value, false, true);
formulaire.options[nb] = nouvel_element;
} |
et voici le code de la page popup
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| function doc(id_op)
{
if (document.layers)
{ // NS 4 et <
return document[id_op];
}
if (document.all)
{ // IE
return document.all[id_op];
}
if (document.getElementById)
{
return document.getElementById(id_op);
}
}
function valid()
{
value = doc('value').value;
text = doc('id_n').value;
opener.ajout('id_op', value, text);
}
<form id="formcache" class="form-signin" action="" method="post" onsubmit="valid();">
<fieldset>
<h2 class="form-signin-heading">Confirmation</h2>
<div>
<center>L'opération <strong>"{{ name }}"</strong> à bien été ajouté."!!</center>
<input type="hidden" name="value" id="value" value="" />
<input type="hidden" class="form-control" id="id_n" maxlength="30" name="name" value=""/></p>
<br>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit" id="id_op" onclick="window.close();">Fermer la fenêtre</button>
</fieldset>
</form> |
Je code en Django d'ou l'apparition de certaine balise mais cela ne change rien pour le code.
Du coup, j'ai -essay�- de transformer ce code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| function doc(id_operation)
{
if (document.layers)
{ // NS 4 et <
return document[id_operation];
}
if (document.all)
{ // IE
return document.all[id_operation];
}
if (document.getElementById)
{
return document.getElementById(id_operation);
}
}
function valid()
{
value = doc('value').value; //$('#value').text();
text = doc('id_name').value;
opener.ajouter('id_operation', value, text);
} |
en ce code
Code:
1 2 3 4
| $("form").submit(function(event) {
$('#value').text();
$('#id_n').text();
}); |
Je ne suis pas trop sur de moi, et pour le code la page principale, je donne ma langue au chat !!
Merci