Click here to Skip to main content
15,892,927 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: disable a onclick function, and enable it Pin
jkirkerx29-Jul-14 6:01
professionaljkirkerx29-Jul-14 6:01 
AnswerRe: disable a onclick function, and enable it Pin
Sibeesh KV24-Sep-14 1:01
professionalSibeesh KV24-Sep-14 1:01 
QuestionParse value from jquery to php and truncate mysql table Pin
Member 1094998617-Jul-14 7:32
Member 1094998617-Jul-14 7:32 
SuggestionRe: Parse value from jquery to php and truncate mysql table Pin
ZurdoDev29-Jul-14 10:13
professionalZurdoDev29-Jul-14 10:13 
Questionweb application for marathi input Pin
Member 104570339-Jul-14 2:37
professionalMember 104570339-Jul-14 2:37 
AnswerRe: web application for marathi input Pin
Graham Breach9-Jul-14 23:31
Graham Breach9-Jul-14 23:31 
AnswerRe: web application for marathi input Pin
Ravindra Bisen18-Jul-14 0:29
Ravindra Bisen18-Jul-14 0:29 
QuestionDate and time validation are not working. Any ideas? <Resolved> Pin
samflex5-Jul-14 12:54
samflex5-Jul-14 12:54 
Experts,

Can someone please help me resolve this problem?

When a user selects start time and end time, if the difference in hours is not at least 4 hours, an alert should be raised.

This works beautifully with asp.net web form.

However, I had to switch to Gridview because I wanted not just the ability to dynamically add more dates as needed, but also be able to submit user's choices to the database.

So, since switching to gridview, the validation is no longer working.

Can someone please give me a helping hand?

Thanks a lot in advance.

PHP
    <script type="text/javascript">

        $(function () {

            $("[id$=txtdate]").datepicker({

                showOn: 'button',

                buttonImageOnly: true,

                buttonImage: 'images/20/calendar200.gif'

            });

        });

    </script>
    <script type='text/javascript'>//<![CDATA[
     $(window).load(function () {
         //Attach click event to button
         $('#btnSave').on('click', function () {
             //Get Values from dropdownlist
             var sHour = $('#startHour').val();
             var sMinutes = $('#startMinutes').val();
             var sAmPm = $('#startAmPm').val();

             var eHour = $('#endHour').val();
             var eMinutes = $('#endMinutes').val();
             var eAmPm = $('#endAmPm').val();

             //create date format from dropdownlist selected values 
             var theDate = $('#txtdate').val()
             var timeStart = new Date(theDate + ' ' + sHour + ':' + sMinutes + ' ' + sAmPm).getHours();
             var timeEnd = new Date(theDate + ' ' + eHour + ':' + eMinutes + ' ' + eAmPm).getHours();

             //Calulate the time difference
             var hourDiff = timeEnd - timeStart;

             //Check if hour difference is less than 4 hours and show the message accordingly
             if (hourDiff < 4) {
                 alert("A mininum of 4 hours is required!");
             }
         });
     });//]]>  

</script>

Then markup
        <asp:gridview ID="Gridview1" runat="server" OnRowDeleting="Gridview1_RowDeleting" ShowFooter="true" AutoGenerateColumns="false">
            <Columns>
            <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
                    <asp:TemplateField HeaderText="Event Date(s)">
                        <ItemTemplate>
                            <asp:TextBox ID="txtdate" runat="server" class = "Calender"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtdate"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Start Time">
                        <ItemTemplate>
                                  <asp:DropDownList id="startHour" runat="server">
                                    <asp:ListItem Value="07">07</asp:ListItem>
                                    <asp:ListItem Value="08">08</asp:ListItem>
                                    <asp:ListItem Value="09">09</asp:ListItem>
                                    <asp:ListItem Value="10">10</asp:ListItem>
                                    <asp:ListItem Value="11">11</asp:ListItem>
                                    <asp:ListItem Selected="True" Value="12">12</asp:ListItem>
                                    <asp:ListItem Value="01">01</asp:ListItem>
                                    <asp:ListItem Value="02">02</asp:ListItem>
                                    <asp:ListItem Value="03">03</asp:ListItem>
                                    <asp:ListItem Value="04">04</asp:ListItem>
                                    <asp:ListItem Value="05">05</asp:ListItem>
                                    <asp:ListItem Value="06">06</asp:ListItem>
                                  </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="startHour"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Minutes">
                        <ItemTemplate>
                                  <asp:DropDownList id="startMinutes" runat="server">
                                    <asp:ListItem Value="00">00</asp:ListItem>
                                    <asp:ListItem Value="15">15</asp:ListItem>
                                    <asp:ListItem Value="30">30</asp:ListItem>
                                    <asp:ListItem Value="45">45</asp:ListItem>
                                 </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="startMinutes"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="AM/PM">
                        <ItemTemplate>
                                 <asp:DropDownList id="startAmPm" runat="server">
                                    <asp:ListItem Value="AM">AM</asp:ListItem>
                                    <asp:ListItem Value="PM">PM</asp:ListItem>
                                 </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="startAmPm"
                                ErrorMessage="*"></asp:RequiredFieldValidator> 
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="End Time">
                        <ItemTemplate>
                                  <asp:DropDownList id="endHour" runat="server">
                                    <asp:ListItem Value="07">07</asp:ListItem>
                                    <asp:ListItem Value="08">08</asp:ListItem>
                                    <asp:ListItem Value="09">09</asp:ListItem>
                                    <asp:ListItem Value="10">10</asp:ListItem>
                                    <asp:ListItem Value="11">11</asp:ListItem>
                                    <asp:ListItem Selected="True" Value="12">12</asp:ListItem>
                                    <asp:ListItem Value="01">01</asp:ListItem>
                                    <asp:ListItem Value="02">02</asp:ListItem>
                                    <asp:ListItem Value="03">03</asp:ListItem>
                                    <asp:ListItem Value="04">04</asp:ListItem>
                                    <asp:ListItem Value="05">05</asp:ListItem>
                                    <asp:ListItem Value="06">06</asp:ListItem>
                                  </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="endHour"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Minutes">
                        <ItemTemplate>
                                  <asp:DropDownList id="endMinutes" runat="server" CSClass="fptextbox12">
                                    <asp:ListItem Value="00">00</asp:ListItem>
                                    <asp:ListItem Value="15">15</asp:ListItem>
                                    <asp:ListItem Value="30">30</asp:ListItem>
                                    <asp:ListItem Value="45">45</asp:ListItem>
                                 </asp:DropDownList>
                             <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="startMinutes"
                                ErrorMessage="*" InitialValue="Select"></asp:RequiredFieldValidator>
                        </ItemTemplate>
                         </asp:TemplateField>
                        <asp:TemplateField HeaderText="AM/PM">
                        <ItemTemplate>
                                 <asp:DropDownList id="endAmPm" runat="server">
                                    <asp:ListItem Value="AM">AM</asp:ListItem>
                                    <asp:ListItem Value="PM">PM</asp:ListItem>
                                 </asp:DropDownList>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="endAmPm"
                                ErrorMessage="*" SetFocusOnError="True"></asp:RequiredFieldValidator>
                        </ItemTemplate>

                        <FooterStyle HorizontalAlign="Right" />
                        <FooterTemplate>
                            <asp:Button ID="ButtonAdd" runat="server" Text="Add Another Event" OnClick="ButtonAdd_Click" />
                        </FooterTemplate>
                      </asp:TemplateField>
                    <asp:CommandField ShowDeleteButton="True" />
                </Columns>
                <FooterStyle BackColor="#AC54AA" Font-Bold="True" ForeColor="white" />
                <RowStyle BackColor="#EFF3FB" />
                <EditRowStyle BackColor="#2461BF" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#AC54AA" Font-Bold="True" ForeColor="white" />
                <AlternatingRowStyle BackColor="White" />
             </asp:gridview>
            <br />
         </div>
        <asp:Button ID="btnSave" runat="server" Text="Send Request" OnClick="btnSave_Click" alt="Send Request" /><br />
        <asp:Label ID="lblResult" style ="font-weight:bold; font-size:large" runat="server"></asp:Label>

 <asp:Button ID="btnSave" runat="server" Text="Send Reservation Request" OnClick="btnSave_Click" alt="Send Request" /><br />


modified 7-Jul-14 12:14pm.

AnswerRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 3:02
mveRichard Deeming7-Jul-14 3:02 
GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:21
samflex7-Jul-14 4:21 
GeneralRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 4:27
mveRichard Deeming7-Jul-14 4:27 
GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:36
samflex7-Jul-14 4:36 
QuestionRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 4:45
mveRichard Deeming7-Jul-14 4:45 
AnswerRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 4:51
samflex7-Jul-14 4:51 
GeneralRe: Date and time validation are not working. Any ideas? Pin
Richard Deeming7-Jul-14 5:17
mveRichard Deeming7-Jul-14 5:17 
GeneralRe: Date and time validation are not working. Any ideas? Pin
samflex7-Jul-14 5:31
samflex7-Jul-14 5:31 
AnswerRe: Date and time validation are not working. Any ideas? Pin
Kornfeld Eliyahu Peter7-Jul-14 3:31
professionalKornfeld Eliyahu Peter7-Jul-14 3:31 
Questionhow to check if user is fan of a facebook page using javascript? Pin
Meax3-Jul-14 6:50
Meax3-Jul-14 6:50 
AnswerRe: how to check if user is fan of a facebook page using javascript? Pin
zeGeek9-Jul-14 14:28
zeGeek9-Jul-14 14:28 
AnswerRe: how to check if user is fan of a facebook page using javascript? Pin
Vfleitao14-Jul-14 22:27
Vfleitao14-Jul-14 22:27 
Questionauto refresh marker on google map with directions Pin
popsompong1-Jul-14 0:10
popsompong1-Jul-14 0:10 
QuestionAngular JS Pin
chauhanvatsal30-Jun-14 20:40
chauhanvatsal30-Jun-14 20:40 
AnswerRe: Angular JS Pin
Kornfeld Eliyahu Peter30-Jun-14 21:41
professionalKornfeld Eliyahu Peter30-Jun-14 21:41 
AnswerRe: Angular JS Pin
gaupoit3-Jul-14 5:27
gaupoit3-Jul-14 5:27 
Questionhow to get data from json url ? Pin
Tamil Purushothaman29-Jun-14 20:43
Tamil Purushothaman29-Jun-14 20:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.