Je suis nouveau sur jquery. J'ai une forme jsp en ce que j'appelle la fonction javascript dans onload. Je veux charger des valeurs dans une liste déroulante qui est en iframe en utilisant jquery-1.4.2.js mais que je ne peux pas ajouter.en utilisant jquery ajouter des valeurs dans un combobox
s'il vous plaît une donner des solutions grâce à l'avance
entendre est mon code jsp
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:getStateCountryDetail(<%=companyId%>,1,<%=countryId%>, <%=stateId%>)">
<table border="0" cellpadding="0" cellspacing="0" width="100%" >
<td width="100%" align="left" style="padding:3px" valign="top">
<table border="0" width="100%" bordercolor="#cce7fa" cellpadding="0" cellspacing="0" style="border-collapse:collapse">
<tr>
<td width="100%" align="left" valign="top">
<iframe id = "applyMultipleInnerFrame" src ="/jsp/careers/applyMultipleCandidateResumeData.jsp?companyid=<%=companyId%>" name="applyMultipleInnerFrame" width="1100px" height="197px" frameborder="0" scrolling="Yes"></iframe>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
Entendre est mon iframe jsp
i contient la liste déroulante
<body>
<form name="applyMultipleCandidateResumeData" method="POST" target="_top" action="http://<%=sName%>/jsp/careers/jobListingMainPage.jsp" enctype="multipart/form-data">
<table align="left" width="100%" border=1 bordercolor="#ff9900" cellspacing=0 cellpadding="0" style="border-collapse:collapse">
<td nowrap width="10%" align="left" style="border-color:#ff9900;color: black; font: 11px verdana;padding:2px" >
<input type="text" maxlength="64" size="9" value="" name="candidateCity_<%= i %>" id="candidateCity_<%= i %>" />
</td>
<td nowrap width="10%" align="left" style="border-color:#ff9900;color: black; font: 11px verdana;padding:2px" >
<select id = "candidateCountry_<%= i %>" name="candidateCountry_<%= i %>" class="controlStyle" onChange="loadState(this.value,'<%=i%>');">
<option value="0">-------- Select --------</option>
</select>
</td>
<td nowrap width="10%" align="left" style="border-color:#ff9900;color: black; font: 11px verdana;padding:2px" >
<select id="candidateState_<%= i %>" name="candidateState_<%= i %>" class="controlStyle">
<option value="0">----------- Select ---------</option>
</select>
</td>
</table>
</form>
</body>
i utilisez le code suivant pour obtenir l'objet iframe en utilisant jqu rès mais je ne sais pas si ce exact ou non
var frm = $("#applyMultipleInnerFrame").contents());
Voici mon code jquery
xmlDoc
est ma réponse jsone qui contient la liste des pays
var frm = $("#applyMultipleInnerFrame").contents());
for(var i=0;i<5;i++) {
if ($(frm).find('input[name=candidateCountry_' + i + ']') && $(frm).find('input[name=candidateCountry_' + i + '] option')) {
$(frm).find('input[name=candidateCountry_' + i + '] option').length = 0;
if (xmlDoc.countryList) {
$(frm).find('input[name=candidateCountry_' + i + '] option')[$(frm).find('input[name=candidateCountry_' + i + '] option').length] = new Option("-- Select --", 0);
for (var k = 0; k < xmlDoc.countryList.length; k++) {
$(frm).find('input[name=candidateCountry_' + i + '] option')[$(frm).find('input[name=candidateCountry_' + i + '] option').length] = new Option(xmlDoc.countryList[k].name, xmlDoc.countryList[k].id);
if ((xmlDoc.countryList[k].id) == dCountryId) {
alert($($(frm).find('input[name=candidateCountry_' + i + ']').text()));
//alert($(frm).find('input[name=candidateCountry_'+i+']').val(dCountryId).text());
//$(frm).find('input[name=candidateCountry_"+i+"] option').eq(dCountryId).attr('selected', 'selected');
}
}
}
//alert($(frm).find('input[name=candidateCountry_'+i+']) option:selected').text());
//processAjaxRequestPost('ajaxRequestPost','SingleListHandler','getStateListDetails', eval('frm.candidateCountry_'+i).options[eval('frm.candidateCountry_'+i).selectedIndex].value);
}
}
Vous devriez vraiment cache '$ (FRM)' au lieu d'appeler encore et : 'var $ frm = $ (frm);' et ensuite utiliser '$ frm' – ThiefMaster