JavaScript help needed

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
CesarePlay
Registered User
Posts: 10628
Joined: 26 Mar 2007, 02:00
Location: In the river of thoughts
Contact:

JavaScript help needed

Post by CesarePlay »

I need urgent help with a javascript function.

The problem:

In one page I click a click to either safety or environment. Depending on the choice it loads the next page differently. The safety one has a bunch of checkboxes that have to be checked to classify an incident. On environment these boxes don't appear.

I got this part working 100%. Now the problem comes in when trying to save the data.

Here is the html

Code: Select all

<div id="Show" runat="server" style="display: block;">
					<table class="block1">
						<tbody>
							<tr id="ViewRC1" vAlign="top">
								<td class="content1" style="WIDTH: 17.04%"><FONT color="red">* </FONT>Criteria<br>
									(Select a Consequence and Likelihood to populate the result.)</td>
								<td colSpan="5">
									<table class="block1" width="100%">
										<tr>
											<td class="content1" style="HEIGHT: 20px">Consequence</td>
											<td class="content3" style="WIDTH: 109px; HEIGHT: 20px"><asp:dropdownlist id="lstProbability" runat="server" onChange="getSevResult();">
													<asp:ListItem Value="-- Not Selected --">-- Not Selected --</asp:ListItem>
													<asp:ListItem Value="low">Low</asp:ListItem>
													<asp:ListItem Value="medium">Medium</asp:ListItem>
													<asp:ListItem Value="high">High</asp:ListItem>
												</asp:dropdownlist></td>
											<td class="content1" style="HEIGHT: 20px">Likelihood&nbsp;</td>
											<td class="content3" style="WIDTH: 110px; HEIGHT: 20px"><asp:dropdownlist id="lstFrequency" runat="server" onChange="getSevResult();">
													<asp:ListItem Value="-- Not Selected --">-- Not Selected --</asp:ListItem>
													<asp:ListItem Value="low">Low</asp:ListItem>
													<asp:ListItem Value="medium">Medium</asp:ListItem>
													<asp:ListItem Value="high">High</asp:ListItem>
												</asp:dropdownlist></td>
											<td class="content1" style="WIDTH: 11.73%; HEIGHT: 20px">Result</td>
											<td class="content3" style="HEIGHT: 20px"><asp:textbox id="sevResult" CssClass="read" ReadOnly="True" Runat="server"></asp:textbox></td>
										</tr>
										<tr>
											<td class="content1"><A class="myStandard" onclick="SeverityDef()" href="javascript: ;"><span style="COLOR: red">*</span>
													Severity Rating</A></td>
											<td class="content3" style="WIDTH: 318px" colSpan="3"><asp:dropdownlist id="lstSeverity" runat="server" Width="312px">
													<asp:ListItem Value="-- Not Selected --">-- Not Selected --</asp:ListItem>
													<asp:ListItem Value="Level 1">Level 1 (Local & Internally Reportable)</asp:ListItem>
													<asp:ListItem Value="Level 2">Level 2 (Legal & Financial Implications)</asp:ListItem>
													<asp:ListItem Value="Level 3 (Geographic Reputation & Significant Financial)">Level 3 (Geographic Reputation & Significant Financial)</asp:ListItem>
												</asp:dropdownlist></td>
											<td class="content1" style="WIDTH: 11.73%"><span style="COLOR: red">*</span> Type</td>
											<td class="content3"><asp:dropdownlist id="lstType" runat="server">
													<asp:ListItem Value="-- Not Selected --">-- Not Selected --</asp:ListItem>
													<asp:ListItem Value="INC">Incident</asp:ListItem>
													<asp:ListItem Value="COM">Complaint</asp:ListItem>
													<asp:ListItem Value="Compliment">Compliment</asp:ListItem>
													<asp:ListItem Value="NC">Non-Conformance</asp:ListItem>
													<asp:ListItem Value="Internal Audit">Internal Audit</asp:ListItem>
													<asp:ListItem Value="External Audit">External Audit</asp:ListItem>
												</asp:dropdownlist></td>
										</tr>
									</table>
								</td>
							</tr>
						</tbody>
					</table>
				</div>
				</TD></TR></TBODY></TBODY>
				<div id="Hide" runat="server">
					<table class="block1">
						<tbody>
							<TR id="safety" style="DISPLAY: none" vAlign="top">
								<td class="content1" style="WIDTH: 31.38%"><A class="myStandard" onclick="SHCD()" href="javascript: ;"><span style="COLOR: red">&nbsp; 
											+ Click To Expand/Collapse</span></A>
								</td>
								<td class="title" colSpan="5"><span style="FONT-WEIGHT: bold; FONT-SIZE: 13px">&nbsp;INCIDENT 
										CLASSIFICATION DETAILS</span>&nbsp;
								</td>
							</TR>
							<tr id="SHCD" style="DISPLAY: none" vAlign="top">
								<td class="content1" style="WIDTH: 31.38%; HEIGHT: 32px">Incident Classification / 
									Consequence</td>
								<td class="content3" style="HEIGHT: 32px" colSpan="5"><span style="COLOR: red">Please 
										select applicable Incident Classification / Consequence</span><br>
									<asp:checkbox id="chkCloseCall" Runat="server" Text="Close Call"></asp:checkbox>&nbsp;&nbsp;
									<asp:checkbox id="chkHPI" Runat="server" Text="HPI"></asp:checkbox>&nbsp;&nbsp;
									<asp:checkbox id="chkInjury" Runat="server" Text="Injury"></asp:checkbox>&nbsp;&nbsp;
									<asp:checkbox id="chkNonComp" Runat="server" Text="Non-Compliance"></asp:checkbox>&nbsp;&nbsp;
									<asp:checkbox id="chkPropDamage" Runat="server" Text="Property Damage"></asp:checkbox></td>
							</tr>
							</tbody>
					</table>
				</div>
These two functions work on a secor variable. The savedata in vb code works fine but the javascript code does not.

I need to get it two check these two data depending on the visible state of the div. I got most of the function but the if part does not work. Here is the javaScript for it:

Code: Select all

if (document.Form1.safety.style.display = "block")
				{ 
					document.Form1.txtAction.value = "Check"
					alert("Please classify the incident.")
					document.all.SHCD.style.display = "block"
					canSubmit = false
				}
			else {
			if (document.Form1.safety.style.display == ""){
			        if (document.Form1.lstSeverity.selectedIndex == 0 && canSubmit){
					alert("Please select a Severity.")
					document.all.ViewRC1.style.display = "block"
					canSubmit = false
					document.Form1.lstSeverity.focus()
				}
			  }
			}

	function safety() {
	  	document.all.safety.style.display == "none" ? document.all.ViewEnv1.style.display = "block" : document.all.safety.style.display = "none"; 
	  	}
	  	
Severity rating is only for environment and must not be checked in the javaScript when safety is selected. As shown in the first code they work on divs. I have no idea how to get the if statement to check this. I tried google and finding no answers to this problem.

When I run it i get the "document.all.safety.style.display == "none"" can't be null or is not an object.
Image
User avatar
Ron2K
Forum Technical Administrator
Posts: 9050
Joined: 04 Jul 2006, 16:45
Location: Upper Hutt, New Zealand
Contact:

Re: JavaScript help needed

Post by Ron2K »

You probably want the getElementById() method of the document object.
Kia kaha, Kia māia, Kia manawanui.
CesarePlay
Registered User
Posts: 10628
Joined: 26 Mar 2007, 02:00
Location: In the river of thoughts
Contact:

Re: JavaScript help needed

Post by CesarePlay »

Ok. I will try that.
Image
CesarePlay
Registered User
Posts: 10628
Joined: 26 Mar 2007, 02:00
Location: In the river of thoughts
Contact:

Re: JavaScript help needed

Post by CesarePlay »

I still can't get it to work. I tried this:

Code: Select all

var  mySelect = document.getElementById("Show");

			theIndx = mySelect.selectedIndex;
			if (mySelect.options[theIndx].value != "none")
				{   
				    document.Form1.txtAction.value = "Check"
					alert("Please classify the incident.")
					document.all.safety.style.display = "block"
					canSubmit = false
				} else {
					if(mySelect.options[theIndx].value == "none"){
						if (document.Form1.lstSeverity.selectedIndex == 0 && canSubmit){
							alert("Please select a Severity.")
							document.all.ViewRC1.style.display = "block"
							canSubmit = false
							document.Form1.lstSeverity.focus()
						}
					}
				}
Now it says object expected.

Edit: the message is "Microsoft JScript runtime error: 'options' is null or not an object"

Edit: This code works for environment:

Code: Select all

window.onload = function()
			{
				alert(document.getElementById("Show").tagName);
			} 
			
			//var  mySelect = document.getElementById("Show");
			//theIndx = mySelect.selectedIndex;
			if (document.getElementById("Show").value != "none")
				{   
					if (document.Form1.lstSeverity.selectedIndex == 0 && canSubmit){
						alert("Please select a Severity.")
						document.all.ViewRC1.style.display = "block"
						canSubmit = false
						ocument.Form1.lstSeverity.focus()
						}
				} else {
					if(document.getElementById("Show") == "none"){
						document.Form1.txtAction.value = "Check"
						alert("Please classify the incident.")
						document.all.safety.style.display = "block"
						canSubmit = false
					}
				}
Image
CesarePlay
Registered User
Posts: 10628
Joined: 26 Mar 2007, 02:00
Location: In the river of thoughts
Contact:

Re: JavaScript help needed

Post by CesarePlay »

I still need help. I need help now not selecting the id environment div when safety is called.
Image
Post Reply