Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling Function from If...Then statement. 2

Status
Not open for further replies.

calandrelli

Technical User
Jun 14, 2002
69
US
I am very new to Javascript and I am having trouble getting a javascript function to work inside of an If...then statement. I downloaded a Javascript function called "DateInput" that produces a datepicker and it uses four variables ( Name, Required, Format, Default Date). I am using it on an ASP page returning a record that contains a date field. Placing this into the code works perfect if the date field is already populate (Date Field name = Due_Date)

Code:
 <script> 
             DateInput('Due_Date', false, 'MM/DD/YYYY',"<%=Due_Date%>")
</Script>

The only issue I have is that when the date filed contains a zero length string the function does not work since the VBScript variable "Due_Date" no longer contains a valid date. I wanted to fix this problem by evaluating the "Due Date" field and then calling the function. If the date is not present then I could run the function with no default date picked and the DateInput function will default to today’s date...but the following does not work. It returns nothing.

Code:
<script>
             If (Due_Date == ""){		 
             DateInput('Due_Date', false, 'MM/DD/YYYY',"<%=Due_Date%>");}
			 else {
			 DateInput('Due_Date', false, 'MM/DD/YYYY');}
         </Script>
 
You are not setting a value for Due_Date up front. You pass the value in inside your first DateInput call but you are trying to evaluate it prior to that. Try this:
Code:
<script>
  var Due_Date = "<%=Due_Date%>";
             If (Due_Date == ""){         
             DateInput('Due_Date', false, 'MM/DD/YYYY',Due_Date);}
             else {
             DateInput('Due_Date', false, 'MM/DD/YYYY');}
         </Script>

It's hard to think outside the box when I'm trapped in a cubicle.
 
Thanks for pointing out the variable thing but it still does not work. I tried both forms of the function without the If...then statement and they work but once inside the if...then statement it is just blank.
 
Code:
            <td width="10" valign="top">&nbsp;</td>
            <td width="315" valign="top" colspan="2"> 
            <span class="fieldname2">Due Date <a class="tooltips2" href="#" onMouseOver="stm(Text[15],Style[3])" onMouseOut="htm()">[?]</a> </span><br>
         <script>
             DateInput('Due_Date', false, 'MM/DD/YYYY');
            </Script>   </tr>
 
Javasript is case sensitive and If doesn't mean a thing to it, while if does.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top