Solved

Field is undefined error

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

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