Solved

Field is undefined error

Posted on 2006-11-09
5
507 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
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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

821 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