[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Field is undefined error

Posted on 2006-11-09
5
Medium Priority
?
525 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

656 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