?
Solved

Field is undefined error

Posted on 2006-11-09
5
Medium Priority
?
521 Views
Last Modified: 2008-02-01
I'm trying to hide the field "case_problemsubnote" and its caption but only if the select box value is not "Other".  I'm getting "Line 16:  case_problemtype is undefined" error.  Can someone help?
------------------------------------------------
<script defer>

if (document.EntryForm.case_problemtype.options[case_problemtype.options.selectedIndex].value!='Other') {
document.getElementById("_Datacase_problemsubnote").style.visibility = "Hidden";
document.getElementById("_Captcase_problemsubnote").style.visibility = "Hidden";
} else {
document.getElementById("_Datacase_problemsubnote").style.visibility = "Visible";
document.getElementById("_Captcase_problemsubnote").style.visibility = "Visible";
}

</script>

<body>

<form name=EntryForm>

<SELECT class=EDIT size=0 name="case_problemtype" >
      <OPTION Value="BuildingExterior">Building Exterior</OPTION>
      <OPTION Value="BuildingWarehouse">Building Interior--Warehouse</OPTION>
                <OPTION Value="Other">Other</OPTION>
      <OPTION VALUE="">--None--</OPTION>
</SELECT>

<SPAN ID=_Captcase_problemsubnote class=VIEWBOXCAPTION>Problem Notes:
</SPAN><br>

<SPAN ID=_Datacase_problemsubnote class=VIEWBOX >
<input type="text" CLASS=EDIT ID="case_problemsubnote" name="case_problemsubnote"  value="" maxlength=40 size=40>
</SPAN>

</form>

</body>
0
Comment
Question by:saturation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Expert Comment

by:bpmurray
ID: 17910213
Here's your problem:
       if (document.EntryForm.case_problemtype.options[case_problemtype.options.selectedIndex].value!='Other') {

Try:
       if (document.getElementById("case_problemtype").options[document.getElementById("case_problemtype").options.selectedIndex].value!='Other') {

instead.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17910240
saturation,

Try using just ...

  if (document.EntryForm.case_problemtype.value!='Other')

I recommend that you make sure all of the attributes in the tags have double quotes around the values.  Depending on the doctype this may be causing an issue to your page.  If that line doesn't work then use this one.  You will need to assign an id attribute to the select tag to match the name attribute.  It is the way I normally do it ...

  if (document.getElementById('case_problemtype').value!='Other')

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 17910253
How about this:

<script defer>
function showSel(theSel){
  var theProblemStyle = document.getElementById("Problem").style;
  if (theSel.value!='Other') {
    theProblemStyle.display = "none";
  } else {
    theProblemStyle.display = "";
  }
}
</script>

<body>

<form name=EntryForm>
<SELECT class=EDIT size=0 name="case_problemtype" onChange="showSel(this)">
     <OPTION Value="BuildingExterior">Building Exterior</OPTION>
     <OPTION Value="BuildingWarehouse">Building Interior--Warehouse</OPTION>
     <OPTION Value="Other">Other</OPTION>
     <OPTION VALUE="">--None--</OPTION>
</SELECT>
<span ID=Problem style="display:none;">
  <SPAN ID=_Captcase_problemsubnote class=VIEWBOXCAPTION>Problem Notes:</SPAN>
  <br>
  <SPAN ID=_Datacase_problemsubnote class=VIEWBOX >
  <input type="text" CLASS=EDIT ID="case_problemsubnote" name="case_problemsubnote"  value="" maxlength=40 size=40>
  <input type=hidden name=_HIDDENcase_problemsubnote value="">
  </SPAN>
</span>
</form>

</body>

0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 17910260
I made a few changes to your code to make it work, here's the working version:

<script defer>
function showHide()
{
      var mySelect = document.EntryForm.elements["case_problemtype"];
      if (mySelect.options[mySelect.selectedIndex].value!='Other') {
      document.getElementById("_Datacase_problemsubnote").style.visibility = "Hidden";
      document.getElementById("_Captcase_problemsubnote").style.visibility = "Hidden";
      }
      else
      {
      document.getElementById("_Datacase_problemsubnote").style.visibility = "Visible";
      document.getElementById("_Captcase_problemsubnote").style.visibility = "Visible";
      }
}

</script>

<body onload = "showHide();">
<form name="EntryForm">
<SELECT class=EDIT size=0 name="case_problemtype" onchange="showHide();">
     <OPTION Value="BuildingExterior">Building Exterior</OPTION>
     <OPTION Value="BuildingWarehouse">Building Interior--Warehouse</OPTION>
     <OPTION Value="Other">Other</OPTION>
     <OPTION VALUE="">--None--</OPTION>
</SELECT>

<SPAN ID=_Captcase_problemsubnote class=VIEWBOXCAPTION>Problem Notes:</SPAN>
<br>
<SPAN ID=_Datacase_problemsubnote class=VIEWBOX >
<input type="text" CLASS=EDIT ID="case_problemsubnote" name="case_problemsubnote"  value="" maxlength=40 size=40>
<input type=hidden name=_HIDDENcase_problemsubnote value=""></SPAN>
</form>

</body>
0
 
LVL 10

Expert Comment

by:dennis_maeder
ID: 17910340
The form is not referenced, so replace the offending line with:
if (document.EntryForm.case_problemtype.options[EntryForm.case_problemtype.options.selectedIndex].value!='Other') {
D
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question