Javascript Function Code Need

Posted by Tg under ASP.NET on 3/6/2013 | Points: 10 | Views : 1571 | Status : [Member] | Replies : 7
Hi,

This is Prakash. I have one Text Box in my page with calender Extender and i validate using callout Extender for my validation.i used javascript for date validation for future date not allowing in the textbox.Now i need a code to check range of date between one date and anothor. Please i need a quick reply.


Thanks

Regards
Prakash




Responses

Posted by: Karthikreddy on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
you can use compare validation with property operator GreaterThan

k@rth!k
karthikreddy08a50@gmail.com

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Pavanandey on: 3/6/2013 [Member] Bronze | Points: 25

Up
0
Down
<asp:TextBox
runat="server"
ID="txtDatecompleted"
/>
<cc2:CalendarExtender
ID="datecompletedExtender"
runat="server"
TargetControlID="txtDatecompleted"
Format="dd MMMM yyyy"
/>
<asp:RangeValidator
runat="server"
ID="RangeValidator1"
Type="Date"
ControlToValidate="txtDatecompleted"
MaximumValue="9999/12/28"
MinimumValue="1000/12/28"
ErrorMessage="enter valid date"
Display="None"
/>
<cc2:ValidatorCalloutExtender
ID="RangeValidator1_ValidatorCalloutExtender"
runat="server"
Enabled="True"
TargetControlID="RangeValidator1">
</cc2:ValidatorCalloutExtender>

Thanks
Pavan Kumar
Mark Answer if this fits the need

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
Hi,
Thanks for reply.
If i have many textbox in the page.I used validation Group .If i use compare or range validation i have to give Validation group.That will work on button click event. i need quick responce once i move from the particular TextBox.Now what i have to do.

Regards
TG


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 3/6/2013 [Member] Starter | Points: 25

Up
0
Down
use this code it will work fine
 <asp:CustomValidator ID="CustomValidator5" runat="server" ClientValidationFunction="Validateddpick"

ControlToValidate="txtDatePosting" ErrorMessage="" ForeColor="Red" ValidateEmptyText="True"
CssClass="validator" ValidationGroup="vgJobPosition"></asp:CustomValidator>
<script language="JavaScript" type="text/javascript">
function Validateddpick(sender, args) {
args.IsValid = true;
var txtDate = document.getElementById('<%= txtDatePosting.ClientID%>')
var re5digit = /^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/]((175[7-9])|(17[6-9][0-9])|(1[8-9][0-9][0-9])|([2-9][0-9][0-9][0-9]))*/;

if ((txtDate.value == "") || (txtDate.value == "mm/dd/yyyy")) {

sender.innerHTML = 'Required !';
args.IsValid = false;
}
else if ((txtDate.value != "") || (txtDate.value != "mm/dd/yyyy")) {
if (!re5digit.test(txtDate.value)) {
sender.innerHTML = 'enter a valid date in mm/dd/yyyy format';
args.IsValid = false;
}
}
}

</script>


k@rth!k
karthikreddy08a50@gmail.com

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 3/7/2013 [Member] Starter | Points: 25

Up
0
Down
Dear Karthik,

In JavaScript getting Error like this "Method not supported 'test'".
!re5digit.test(txtDate.value) in this line.wats the solution.

Regards
TG

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Karthikreddy on: 3/7/2013 [Member] Starter | Points: 25

Up
0
Down
HI tg

use this code i checked it


<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<script language="JavaScript" type="text/javascript">
function Validateddlastpick() {
//args.IsValid = true;
var txtDate = document.getElementById('<%= TextBox1.ClientID%>')
var txtDate1 = document.getElementById('<%= TextBox2.ClientID%>')
var re5digit = /^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/]((175[7-9])|(17[6-9][0-9])|(1[8-9][0-9][0-9])|([2-9][0-9][0-9][0-9]))*/;
if ((txtDate1.value == "") || (txtDate1.value == "mm/dd/yyyy")) {
alert('Required');
}
else if ((txtDate1.value != "") || (txtDate1.value != "mm/dd/yyyy")) {
if (!re5digit.test(txtDate1.value)) {
alert("enter a valid date in mm/dd/yyyy format");
}
}
if (((txtDate.value > txtDate1.value) || (txtDate.value == txtDate1.value))&&(txtDate1.value != "mm/dd/yyyy")) {
alert("Last Date should be greater than Posting Date !");
}
}

</script>
<asp:Button ID="Button1" runat="server" OnClientClick="Validateddlastpick()" Text="Button" />



k@rth!k
karthikreddy08a50@gmail.com

Tg, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tg on: 3/7/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Karthik ,

Thank you so much for your reply.I don't need when button click event fires.I need when Textbox focus move.so i added Onblur in that i gave js,but in js that test method not accepted.whether i have to add any namespace or its built in function.
Here below i put my code for example.
<td>
<asp:TextBox ID="date" runat="server" Height="18px" Width="150px" MaxLength="10"
CssClass="txtbx"
ontextchanged="date_TextChanged" onblur="Validate() "></asp:TextBox>
<asp:CalendarExtender ID="date_CalendarExtender" runat="server" Enabled="True"
TargetControlID="date" Format="dd/MM/yyyy" PopupButtonID="ImageButton1"
DaysModeTitleFormat="dd/MM/yyyy" TodaysDateFormat="dd/MM/yyyy" OnClientDateSelectionChanged="CheckForPastDate">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="San1" runat="server"
ControlToValidate="date" ErrorMessage=" Date is Required"
SetFocusOnError="True" ValidationGroup="f" Display="None"></asp:RequiredFieldValidator>
<asp:ValidatorCalloutExtender ID="San1_ValidatorCalloutExtender" runat="server"
Enabled="True" TargetControlID="San1" PopupPosition="Left">
</asp:ValidatorCalloutExtender>

<br />
</td>

In the above code i used two js.one for calender extender(OnClientDateSelectionChanged="CheckForPastDate") to do not allow future date.next one is this(onblur="Validate()") validate event.I need solution when move focus in the textbox this event have to fire if i give wrong format.

Note:-
I used Validation Group also for buuton click event.


Regards
tg


Tg, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response