[A moitié Résolu] getElementById.value problème d'encoding et decoding sous UTF-8
Bonjour à tous.
Bon voilà j'ai un truc bizarre qui se passe quand je récupère la valeur d'un input pour la mettre dans un autre input avant de soumettre un formulaire.
Tous les formulaires ont accept-charset="UTF-8"
Toutes les pages ont le meta tag
Code:
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"/>
J'utilise simplement deux forumaires
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| <form accept-charset="UTF-8" id="participants-1" name="participants-1" method="post" onsubmit="return checkBeforeUpdate('1')" action="updatePartInfoServlet">
<input type="hidden" id="nonProfOrg1" value="0"/>
<input type="hidden" id="publicBody1" value="1"/>
<input type="hidden" id="researchOrg1" value="1"/>
<input type="hidden" id="highEducation1" value="0"/>
<input type="hidden" id="costModel1" value="SIMPLE"/>
<input type="hidden" id="partName1" value="&é"'(§è!çà)"/>
<input type="hidden" id="Pemails1" value="stessy@gmail.com"/>
<input type="hidden" id="partID" name="partID" value="1"/>
<input type="hidden" id="partnerId" name="partnerId" value="167674"/>
<input type="hidden" id="clearPIC1" name="clearPIC1" value="0"/>
<input type="hidden" id="ori_pic_main1" name="ori_pic_main1" value="999999967"/>
<!--input type="hidden" id="ori_checkdigits" name="ori_checkdigits" value=""/-->
<input type="hidden" id="getPicOK1" name="getPicOK1" value="no"/>
<input type="hidden" id="samePic1" name="samePic1" value="yes"/>
<table border="0" summary="content" width="100%">
<tr>
<td colspan="2" align="center">
<div id="cost-model-part-status-1" style="background-color:rgb(255,255,224);position:relative; top:15px; padding:0 0 0 0; margin:0;border:1px solid #F87217;" align="center">
<div class="title" style="text-align:center; line-height:2.5em; position:relative; top:-10px; left:-55px; background-color:rgb(255,255,224); height:25px; width:190px; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><span class="h4p">Participant Identification Code</span></div>
<div class="button" style="text-align:center; line-height:2.5em; position:absolute; top:-10px; right:10px; background-color:rgb(255,255,224); height:25px; width:auto; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><a href="#" onClick="openHelp('')"><span class="h3p">need info?</span></a></div>
<table width="95%" border="0">
<tr>
<td align="left"><span class="h3p">PIC</span></td>
<td width="35%" align="left"><input type="text" id="pic_main1" name="pic_main1" value="999999967" size="9" maxlength="9"><!--input type="text" class="smallbox" id="checkdigits" name="checkdigits" value="" size="2" maxlength="2"--></td>
</tr>
<tr>
<td align="left"><input type="button" value="Clear PIC Info" onclick="clearPic('1')"></td>
<td width="%30" align="left"><input type="button" ID="getPic1" value="Get PIC Info" onclick="newPageAjaxReq('picProposal?action=picAJAX','1')"></td>
</tr>
</table>
</div>
</td>
<td align="center" rowspan="3">
<div id="add-part-status-info-1" style="background-color:rgb(255,255,224);position:relative; top:25px; padding:0 0 0 0; margin:0;border:1px solid #F87217;">
<div class="title" style="text-align:center; line-height:2.5em; position:relative; top:-10px; left:-50px; background-color:rgb(255,255,224); height:25px; width:180px; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><span class="h4p">Status of your organisation</span>
</div>
<div class="button" style="text-align:center; line-height:2.5em; position:absolute; top:-10px; right:10px; background-color:rgb(255,255,224); height:25px; width:auto; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><a href="#" onClick="openHelp('statusOfOrg.html')"><span class="h3p">need info?</span></a>
</div>
<table width="100%">
<tr>
<td width="70%" align="right" style="font-weight:lighter">Non Profit Organisation</td>
<td width="30%" align="left">
<input type="radio" name="npo" id="npo1yes" value="1"/>yes
<input type="radio" name="npo" id="npo1no" value="0"/> no
</td>
</tr>
<tr>
<td width="70%"align="right">Public Body</td>
<td width="30%"align="left">
<input type="radio" name="pb" id="pb1yes" value="1"/>yes
<input type="radio" name="pb" id="pb1no" value="0"/> no
</td>
</tr>
<tr>
<td width="70%"align="right">Research Organisation</td>
<td width="30%" align="left">
<input type="radio" name="ro" id="ro1yes" value="1"/>yes
<input type="radio" name="ro"id="ro1no" value="0"/> no
</td>
</tr>
<tr>
<td width="70%" align="right">Higher, secondary education establishment</td>
<td width="30%" align="left">
<input type="radio" name="he" id="he1yes" value="1"/>yes
<input type="radio" name="he" id="he1no" value="0"/> no
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr><td> </td></tr><tr>
<td align="center"><span class="h3p">Organisation Short Name</span>
</td>
<td align="center"><input type="text" style="border-bottom:1px solid;"
name="shortOrgName" id="shortOrgName1"
value="&é"'(§è!çà)" maxLength="18"/></td>
</tr>
<tr>
<td align="center"><span class="h3p">Participant E-mail(s)</span>
</td>
<td align="center"><input type="text" name="partEmail" id="partEmail1" value="stessy@gmail.com"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<div id="cost-model-part-status-1" style="background-color:rgb(255,255,224);position:relative; top:5px; padding:0 0 0 0; margin:0;border:1px solid #F87217;" align="center">
<div class="title" style="text-align:center; line-height:2.5em; position:relative; top:-5px; left:-55px; background-color:rgb(255,255,224); height:25px; width:190px; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><span class="h4p">Method of determining Indirect Costs</span></div>
<div class="button" style="text-align:center; line-height:2.5em; position:absolute; top:-5px; right:10px; background-color:rgb(255,255,224); height:25px; width:auto; font-weight:bold; padding:0 10px 0 10px; border:1px solid #F87217;"><a href="#" onClick="openHelp('indirectCostsInfo.html')"><span class="h3p">need info?</span></a></div>
<table width="95%" border="0">
<tr>
<td width="50%" align="right"></td>
<td width="50%" align="left">
<select name="costModel" id="cm1">
<option value=""></option>
<option value="REAL">Real Indirect Cost</option>
<option value="SIMPLE">Simplified Method</option>
<option value="FLAT_TRANS">Special Transition Flat Rate</option>
<option value="FLAT_STD">Standard Flat Rate</option>
<option value="LUMP">Lump sum (for ICPC)</option>
</select>
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td height="30" align="left"></td>
<td height="30" align="left"></td>
<td height="30" align="center"><input name="add" type="submit" value="Update Participant Information"/></td>
</tr>
</table>
</form> |
et
Code:
1 2 3 4 5 6
| <form name="pf" accept-charset="UTF-8" action="picConfirmation.jsp" method="post" >
<input type="hidden" name="partId" value=""/>
<input type="hidden" name="pic" value=""/>
<input type="hidden" name="orgNamePf" value=""/>
<input type="hidden" name="orgEmailPf" value=""/>
</form> |
Ensuite le javascript suivant (le code n'est pas complet, c'est juste la partie qui récupère la valeur pour la mettre dans un autre field)
Code:
1 2
| document.pf.orgNamePf.value = document.getElementById('shortOrgName1').value;
document.pf.orgEmailPf.value = document.getElementById('partEmail1').value; |
Voici comme exemple ce que j'ai quand je rentre les caractères suivant:
&é"'(§è!çà)
Et voilà ce que j'ai dans le deuxième field après la copie:
&é"\'(§è!çà )
Si vous souhaitez tenter l'expérience vous même vous pouvez aller ici:
https://www.epss-fp7.org/epsspic/login.jsp
username: RTG67H3LSJ
password: azerty123
Aller dans "Proposal Setup"
Cliquer sur "edit details" pour le premier participant
Où vous verrez la valeur: 999999967 , remplacer là par 000000195
Cliquez sur le bouton "get PIC info"
Cliquez sur "accept"
Et voyez le beau résultat que cela me sort.
Alors que tout est en UTF-8, cela ne fonctionne pas.
On dirait que le javascript encode les caractères spéciaux sans les décoder.
A moins que cela ne soit autre chose, mais alors je ne sais pas quoi.
Si quelqu'un a une idée lumineuse, ou pourrait m'orienter pour effectuer des tests plus approfondis, cela me serait d'un grand secours.
D'avance merci pour vos réponses.