|
| |
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
Whats wrong with my javascript? - 1/17/2007 10:28:05
Hello: I have a conditional javascript that works fine if I take out the line: else if (document.frmEditProject.Project_Submission_Date_History.value == null) If I use the null statment the alert doesn't come up? what am I doing wrong? I want it to display the alert message if there is a value and compare it with another one else if the value is null then exit and don't display the alert and exit. Here's the full code: <script language="Javascript"> function ConfirmResubmit() { if (document.frmEditProject.Project_Submission_Date_History.value != document.frmEditProject.CurrentDate.value) { alert("NOTICE: Changing the Project Sufficiency Date will resubmit this project!"); } else if (document.frmEditProject.Project_Submission_Date_History.value == null) } </SCRIPT>
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 10:40:26
I don't think a form value can be null. Does this make a difference? else if (document.frmEditProject.Project_Submission_Date_History.value == "")
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 10:53:33
It works with the null statement if it's the only condition...so you can have a null value on a form and use it in the statment. I'm just having a problem with having both conditions work together.
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 11:00:20
I am not sure why the else if statement is in there given that you don't tell the code to do anything if the else if statement is true. What do you want to happen if Project_Submission_Date_History is null?
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 11:06:39
not to display the alert box.
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 11:09:38
Try this: <script language="Javascript"> function ConfirmResubmit() { if (document.frmEditProject.Project_Submission_Date_History.value != document.frmEditProject.CurrentDate.value && document.frmEditProject.Project_Submission_Date_History.value != null) { alert("NOTICE: Changing the Project Sufficiency Date will resubmit this project!"); } } </SCRIPT>
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 11:20:22
I still get the message if the field is blank. I tried your idea before I posted the problem 10 ways to sunday and still can't seem to figure this out. I even changed the null to the "" and '' etc...this is the devil in the details that drive me crazy! I really appreciate your help and taking the time to look at this....any other ideas?
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 11:46:06
Should work. Here is a sample page testing the theory. Perhaps looking it over will help: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript">
function ConfirmResubmit() {
if (document.form1.t1.value != document.form1.t2.value && form1.t2.value != "")
{
alert("NOTICE: Changing the Project Sufficiency Date will resubmit this project!");
}
}
</SCRIPT>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="ConfirmResubmit()">
<label>Date 1
<input type="text" name="t1">
</label>
<p>
<label>Date 2
<input type="text" name="t2">
</label>
</p>
<p>
<label>
<input type="submit" name="Submit" value="Submit">
</label>
</p>
</form>
</body>
</html>
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 12:40:20
Not sure what your getting at here....it's exactly the same as the previous post? The problem is that I am pulling the value of Project_Submission_Date_History from a Sql Database and it is a null value for sure and if you take the 1st part of the condition out and only evaluate the null value it works fine and recognizes the null value as true. I know there must be a way to do this....I can't be the only one who has encountered this problem but I really do appreciate your help and thank you!
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 13:17:40
Just to troubleshoot, change the function as shown below and then test with an null value in Project_Submission_Date_History <script language="Javascript"> function ConfirmResubmit() { /*if (document.frmEditProject.Project_Submission_Date_History.value != document.frmEditProject.CurrentDate.value && document.frmEditProject.Project_Submission_Date_History.value != null) { alert("NOTICE: Changing the Project Sufficiency Date will resubmit this project!"); } */ alert(document.frmEditProject.Project_Submission_Date_History.value) } What gets written to the alert? </SCRIPT>
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 14:15:05
I am kind of grasping at straws here, but this may work: <script language="Javascript"> function ConfirmResubmit() { if (document.frmEditProject.Project_Submission_Date_History.value != document.frmEditProject.CurrentDate.value && document.frmEditProject.Project_Submission_Date_History.value.length < 1) { alert("NOTICE: Changing the Project Sufficiency Date will resubmit this project!"); } } </SCRIPT>
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 15:13:28
Another great outside the box idea....but...now it doesn't show the alert box even if a value exists in the Project_Submission_Date_History field. The complete opposite of using the null or "" .
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 15:20:22
Reverse the > and change the 1 to zero like this: document.frmEditProject.Project_Submission_Date_History.value.length > 0 Those greater than/ less than things get me every time.
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 15:27:02
Nope...now we are back to the alert being displayed for both conditions again....
|
|
|
|
BeTheBall
Posts: 6381 Joined: 6/21/2002 From: West Point Utah USA Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 15:31:20
OK. Go back to where I had you put the value of the field in an alert, but let's put the value's length into an alert so instead of: alert(document.frmEditProject.Project_Submission_Date_History.value) use: alert(document.frmEditProject.Project_Submission_Date_History.value.length) Then post back with what is put into the alert.
_____________________________
Duane Some people are like Slinkies . . . Not really good for anything . . . . . But they still bring a smile to your face when you push them down a flight of stairs.
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 15:44:03
GOT IT!!!!!! Man.....I owe you big time! THANK YOU! You have a new best friend here in sunny florida! I changed the line to: if (document.frmEditProject.Project_Submission_Date_History.value != document.frmEditProject.CurrentDate.value && document.frmEditProject.Project_Submission_Date_History.value.length > 1)
|
|
|
|
jfrankland
Posts: 89 Joined: 5/5/2004 From: Port Saint Lucie, Florida Status: offline
|
RE: Whats wrong with my javascript? - 1/17/2007 16:06:35
Yep I know I will too.......but anyone reading this post should keep in mind that I was using Sql server and the field was a date/time field so maybe a null value being pulled in from Sql server into a textbox sees the date/time field as at least a character of 1.
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|