hai friends, for my application we are using both internet explorer and mozilla firebox browser . iam calling a javascript function on change of value in a select box. onChange = javascript:goSelected(this.options[this.selectedIndex].innerText); in internet explorer the value is showing in alert inside goselected method, but for mozilla firebox the value is showing undefined. can someone give a solution
now I get it <html> <head> <script language="javascript"> function goSelected( data ) { if( navigator.appName ) { alert( data.options[data.selectedIndex].innerText ); } else { alert( data.value ); } } </script> </head> <body> <select name="select" onChange="goSelected( this );" > <option>ONE</option> <option>TWO</option> </select> </body> <html> HTML:
thank u krakjoe.... i will send u the exact scenario my javascript function -- // goSelected is called when a different value is selected from Part/Rev drop down list box function goSelected(selText) { alert('1 parameter',selText); alert(selText); var formValResult = validatePartComplianceResponse(PartSurveyResponseForm); if (formValResult == false) { return false; } var selTextArray = selText.split(" "); if ( document.PartSurveyResponseForm.modified.value == 'YES' ) { document.PartSurveyResponseForm.selPartNumber.value = selTextArray[0]; document.PartSurveyResponseForm.selPartRev.value = selTextArray[2]; document.PartSurveyResponseForm.action = "<%=request.getContextPath()%>/SavePartSurveyAction.do"; } else { document.PartSurveyResponseForm.partNumber.value = selTextArray[0]; document.PartSurveyResponseForm.partRev.value = selTextArray[2]; document.PartSurveyResponseForm.action = "<%=request.getContextPath()%>/PrePartSurveyAction.do"; } alert('before submit'); document.PartSurveyResponseForm.submit(); return true; } jsp code -- <select name="selectedPartNumber" onchange="javascript:goSelected(this.options[this.selectedIndex].innerText);"> <logic:iterate id="partCompDTO" name="PartSurveyResponseForm" property="partCompSurveyList"> <option value='<bean:write name="partCompDTO" property="tycoPartNumber"/>' <% String partRevInfo = partCompDTO.toString(); if ( selPartRevInfo.equals(partRevInfo) ) { %> selected <% } %> > <bean:write name="partCompDTO" property="tycoPartNumber"/> rev <bean:write name="partCompDTO" property="partRev"/> </option> </logic:iterate> </select>
i feel the change should be in the higlighted part. for IE value is coming but for mozilla its giving undefined <select name="selectedPartNumber" onchange="javascript:goSelected(this.options[this.selectedIndex].innerText);"> it will be very helpfull if u can solve this
I did already give you a solution, you need to pass the entire select object to the function as the gecko engine handles the select tag differently from IE, by passing the object you can then test to see which engine is being used : if( navigator.appName ) and the set your value accordingly, the only difference is passing the entire object and then using that if condition there to handle the object differently.