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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If 2 dates equal a checkbox gets flaged

Status
Not open for further replies.

mcallaghan

IS-IT--Management
Mar 22, 2005
43
US
I have 2 fields on a page where one date field is automatically loaded when the screen is loaded with todays date the second field a user picks a date. I have a javascript that opens a calender and they choose a date. What I am looking for is if these 2 date are equal to put it in the check box. Can anyone please help me. It would be most appreciated.



<script type="text/javascript">

function CheckValue(this)
{
var A=document.getElementById("ProposedD")
var B=document.getElementById("Drequest")
If document.getElementById("ProposedD")==document.getElementById("Drequest");
document.getElementById("Emergency").checked=true;
}

</script>

<input name="Drequest" value="<%=Date()%>">

<p>Proposed Implementation Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input onclick="ds_sh(this)";onchange="CheckValue(this)"; name="ProposedD" readonly="readonly" style="cursor: text"/>

****************************************************
***the onclick="ds_sh(this)"; method just sets the calender date
*****************************************************

<p>Emergency Change Request: <input type="CHECKBOX" name="Emergency"></p>

Thanks

 
Hi

First of all correct the syntax errors :
[ul]
[li]JavaScript is case sensitive and [tt]if[/tt] must be written in lowercase[/li]
[li]in JavaScript the [tt]if[/tt]'s condition must be enclosed in parenthesis ( () )[/li]
[/ul]
Code:
[red]i[/red]f [red]([/red]document.getElementById("ProposedD")==document.getElementById("Drequest")[red])[/red];
Then correct the logic errors :
[ul]
[li]you have a semicolon ( ; ) after the [tt]if[/tt], which marks the end of the next statement, and [tt]if[/tt] only executes the next statement, so only up to that semicolon[/li]
[li]you compare two distinct objects instead of their [tt]value[/tt] properties, so will never give [tt]true[/tt][/li]
[/ul]
Code:
if (document.getElementById("ProposedD")[red].value[/red]==document.getElementById("Drequest")[red].value[/red])
And finally correct the plain stupidity. ( Sorry for talking like this, but seeing your profile probably you will never reply, anyway... )
[ul]
[li]you did not give [tt]id[/tt] attributes to your [tt]input[/tt] elements, so you can not reference them like that[/li]
[li]you already have the references to the objects in the A and B variables, so use them instead of another pair of [tt]getElementById()[/tt][/li]
[/ul]
Code:
<script type="text/javascript">

function CheckValue(this)
{
  var A=document.getElementById("ProposedD")
  var B=document.getElementById("Drequest")
  if ([red]A[/red].value==[red]B[/red].value)
    document.getElementById("Emergency").checked=true;
}

</script>

<input name="Drequest" value="<%=Date()%>" [red]type="text"[/red] [red]id="Drequest"[/red]>

<p>Proposed Implementation Date: <input onclick="ds_sh(this)" onchange="CheckValue(this)" name="ProposedD" readonly="readonly" style="cursor: text" [red]type="text"[/red] [red]id="ProposedD"[/red]/>

<p>Emergency Change Request: <input type="CHECKBOX" name="Emergency" [red]id="Emergency"[/red]></p>
By the way
[ul]
[li]the [tt]type[/tt] attribute of the [tt]input[/tt] elements is mandatory[/li]
[li]the attribute must be separated with whitespace not semicolor ( ; )[/li]
[li]in this case you do not need to pass [tt]this[/tt] as parameter to you function[/li]
[li]do not use the language's keywords like [tt]this[/tt] as formal parameter[/li]
[/ul]

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top