You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Joe Yuen <jo...@chisq.com> on 2008/03/25 15:40:52 UTC
Javascript error using struts select tag
I am trying to use the <html:select> tag in my jsp page but am getting the following javascript error,
Microsoft JScript runtime error: Object expected.
In my jsp page I have:
<table align="left" class="tableGold">
<tr>
<th align="left" bgcolor="#EEE8AA"><font size="-1" color="#ff0000">*</font><bean:message key="table.head.category"/></th>
</tr>
<tr>
<td align="center" valign="middle" >
<div>
<div style="{float: left;}" >
<html:select styleId="category" property="devicecategoryid" onchange="selectDevOrStent()">
<html:option value=""><bean:message key="select.list.device.category"/></html:option>
<html:options collection="DeviceCategory" property="id" labelProperty="description"/>
</html:select>
</div>
<div id="otherdev" style="{float: left; display: none; font-family: Arial, Helvetica, sans-serif; font-size: xx-small; vertical-align: middle; padding-left: 50px; line-height: 1.2em}">
<html:text property="other" size="35" maxlength="60" onfocus="clearOther()" value = "Enter Device Description" />
</div>
</div>
</td>
</tr>
</table>
Here is the javascript funtion that is called when a onchange event is detected:
function selectDevOrStent(){
alert("In SelectDevOrStent");
var category = id("category").options[id("category").selectedIndex].value;
var categoryText = id("category").options[id("category").selectedIndex].text;
//alert("categoryText = " + categoryText);
if(categoryText == 'Stents'){
//alert("Stent selected");
id("stent").style.display = "block";
id("dev").style.display = "none";
id("otherdev").style.display = "none";
getSelectList("category", "StentManufacturerSelect.do", stentmanufcallback);
}else if(categoryText == 'Joint Replacement'){
//alert("Joint Replacement selected");
document.DeviceInputForm.devicetypeid.disabled='true';
document.DeviceInputForm.manufacturer.disabled='true';
document.DeviceInputForm.modelnumber.disabled='true';
getSelectList("category", "DeviceLocationSelect.do?devicecategoryid=" + escape(id("category").value), locationcallback);
id("dev").style.display = "block";
id("stent").style.display = "none";
id("otherdev").style.display = "none";
}else if(categoryText == 'Other'){
//alert("Other selected");
id("otherdev").style.display = "block";
id("stent").style.display = "none";
id("dev").style.display = "none";
}else{
//alert("Stent not selected");
id("stent").style.display = "none";
id("dev").style.display = "block";
id("otherdev").style.display = "none";
getSelectList("category", "DeviceTypeSelect.do?devicecategoryid=" + escape(id("category").value), devicecallback);
}
}
Everything is fine, I can see the select box and all the options are there but when I trigger a onchange event I get the error. Can anyone see what I am doing wrong?
Thanks.
Re: Javascript error using struts select tag
Posted by Laurie Harper <la...@holoweb.net>.
Since html:submit doesn't emit any Javascrip, the error has to be in
your custom Javascript code. That came through somewhat unreadably
formatted, though, and you didn't include its dependencies so it's tough
to debug from here... I would strongly recommend installing Firefox +
Firebug and stepping through your code in the debugger to figure out the
problem.
L.
Joe Yuen wrote:
>
>
>
> I am trying to use the <html:select> tag in my jsp page but am getting the following javascript error,
>
> Microsoft JScript runtime error: Object expected.
>
> In my jsp page I have:
>
> <table align="left" class="tableGold">
>
> <tr>
>
> <th align="left" bgcolor="#EEE8AA"><font size="-1" color="#ff0000">*</font><bean:message key="table.head.category"/></th>
>
> </tr>
>
> <tr>
>
> <td align="center" valign="middle" >
>
> <div>
>
> <div style="{float: left;}" >
>
> <html:select styleId="category" property="devicecategoryid" onchange="selectDevOrStent()">
>
> <html:option value=""><bean:message key="select.list.device.category"/></html:option>
>
> <html:options collection="DeviceCategory" property="id" labelProperty="description"/>
>
> </html:select>
>
> </div>
>
> <div id="otherdev" style="{float: left; display: none; font-family: Arial, Helvetica, sans-serif; font-size: xx-small; vertical-align: middle; padding-left: 50px; line-height: 1.2em}">
>
> <html:text property="other" size="35" maxlength="60" onfocus="clearOther()" value = "Enter Device Description" />
>
> </div>
>
> </div>
>
> </td>
>
> </tr>
>
> </table>
>
>
>
> Here is the javascript funtion that is called when a onchange event is detected:
>
>
>
> function selectDevOrStent(){
>
> alert("In SelectDevOrStent");
>
> var category = id("category").options[id("category").selectedIndex].value;
>
> var categoryText = id("category").options[id("category").selectedIndex].text;
>
> //alert("categoryText = " + categoryText);
>
> if(categoryText == 'Stents'){
>
> //alert("Stent selected");
>
> id("stent").style.display = "block";
>
> id("dev").style.display = "none";
>
> id("otherdev").style.display = "none";
>
> getSelectList("category", "StentManufacturerSelect.do", stentmanufcallback);
>
> }else if(categoryText == 'Joint Replacement'){
>
> //alert("Joint Replacement selected");
>
> document.DeviceInputForm.devicetypeid.disabled='true';
>
> document.DeviceInputForm.manufacturer.disabled='true';
>
> document.DeviceInputForm.modelnumber.disabled='true';
>
> getSelectList("category", "DeviceLocationSelect.do?devicecategoryid=" + escape(id("category").value), locationcallback);
>
> id("dev").style.display = "block";
>
> id("stent").style.display = "none";
>
> id("otherdev").style.display = "none";
>
> }else if(categoryText == 'Other'){
>
> //alert("Other selected");
>
> id("otherdev").style.display = "block";
>
> id("stent").style.display = "none";
>
> id("dev").style.display = "none";
>
> }else{
>
> //alert("Stent not selected");
>
> id("stent").style.display = "none";
>
> id("dev").style.display = "block";
>
> id("otherdev").style.display = "none";
>
> getSelectList("category", "DeviceTypeSelect.do?devicecategoryid=" + escape(id("category").value), devicecallback);
>
> }
>
> }
>
> Everything is fine, I can see the select box and all the options are there but when I trigger a onchange event I get the error. Can anyone see what I am doing wrong?
>
>
>
> Thanks.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org