Whats wrong with my javascript? (Full Version)

All Forums >> [Web Development] >> General Web Development



Message


jfrankland -> 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 -> 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 == "")




jfrankland -> 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 -> 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?




jfrankland -> RE: Whats wrong with my javascript? (1/17/2007 11:06:39)

not to display the alert box.




BeTheBall -> 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>




jfrankland -> 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 -> 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>




jfrankland -> 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 -> 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>




jfrankland -> RE: Whats wrong with my javascript? (1/17/2007 13:29:24)

great idea! what I got was a blank box see screen shot below


[image]local://upfiles/11230/A5718CBBA5FB4360B82D2EE3A0FC55DF.jpg[/image]




BeTheBall -> 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>




jfrankland -> 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 -> 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.




jfrankland -> 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 -> 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.




jfrankland -> 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)






BeTheBall -> RE: Whats wrong with my javascript? (1/17/2007 15:50:50)

Glad you got it.

Now I will sit and wonder the rest of the day why javascript thinks the length of the field's value is 1. [&:]




jfrankland -> 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.





Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.078125