Solved

Field is undefined error

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now