Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:55:57+00:00 2026-06-01T15:55:57+00:00

I am trying to validate two fields. One is open time and the other

  • 0

I am trying to validate two fields. One is open time and the other one is close time. My validation should check if the close time has a value anything else than “00” my open time should have a value greater than “00” as well.

My question is, what am I doing wrong? I know I must have an error in my function.

This is the validation that I wrote so far:

<script type="text/javascript">

function hoursFunction(formObject, formField, fieldValue)
{  
  var closeHours = document.getElementById('closeHours#CountVar#');
  var openHours = document.getElementById('openHours#CountVar#');

  if(closeHours != "00" && openHours == "00")
  {
    sfm_show_error_msg('Enter a valid opening time');
  }
}

And this a sample of my form

<form id="hoursForm" action="physician_businessHours.cfm?docID=<cfoutput>#docid#</cfoutput>" method="post" onsubmit="hoursFunction();">
            <input type="hidden" name="postitnow" value="yes">


                    <table border="1">

                    <tr>
                        <th>Day</th><th>Open Time</th><th>Close Time</th>
                    </tr>


                    <cfloop from="1" to="7" index="CountVar">

                    <cfset dayFound= 0>
                    <tr>
                        <td><cfif CountVar eq 1>Mon<cfelseif CountVar eq 2>Tues<cfelseif CountVar eq 3>Wednes<cfelseif CountVar eq 4>Thurs<cfelseif CountVar eq 5>Fri<cfelseif CountVar eq 6>Satur<cfelseif CountVar eq 7>Sun</cfif>day</td>

                        <cfoutput>

                        <td>   
                        <select id="openHours#CountVar#" name="openHours#CountVar#">
                         <cfloop query="doctorHours">
                        <cfloop from="00" to="23" index="OpenHours">  
                        <option  value="#openHours#"<cfif TimeFormat(doctorHours.openTime,'HH') EQ OpenHours AND CountVar EQ doctorHours.day > selected="selected"</cfif>>#OpenHours#</option>
                        </cfloop>
                        </cfloop>
                        </select>
                         </td>

     <td>     
                        <select id="closeHours#CountVar#" name="closeHours#CountVar#">
                        <cfloop query="doctorHours">
                        <cfloop from="00" to="23" index="closeHours">  
                        <option value="#closeHours#"
                        <cfif TimeFormat(doctorHours.closeTime,'HH') EQ closeHours AND CountVar EQ doctorHours.day  > selected="selected"</cfif>>#closeHours#</option>
                        </cfloop>
                        </cfloop>
                        </select>
                        </td>
                         </tr>

      <input type="hidden" name="Validate" onValidate="hoursFunction" message="You must select an opening hour">

     <input type="submit" value="Update" id="Submit">
                    '
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:55:58+00:00Added an answer on June 1, 2026 at 3:55 pm

    This is the code that I wrote and it works fine so far:

    function hoursFunction()
    {  
    
        var i = 0;
        var openHour;
        var closeHour;
    
        for(i=1;i<8;i++)
        {
         openHour = document.getElementById("openHours" + i).value;
         closeHour= document.getElementById("closeHours" + i).value;
    
        if(openHour > closeHour)
        {   
            document.getElementById('error').innerHTML= "Error at " + i;  
            return false; 
        }
        document.getElementById('error').innerHTML= "No Error occured";  
        return true;
        }
    }
    

    My issue now is that when I submit the form it seems that the form is doing a refresh and is deleting all of my data…
    Any thoughts on that?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery Validation plugin and trying to validate two time fields. I
I am trying to validate two fields one is a number and other is
I am trying to validate a phone number which is contained over two fields.
I'm trying to remote validate a field by looking at two different fields. The
I was trying to validate an XML signature. The validation according to this tutorial
I have two logical groups of input fields I need to validate separately using
I'm trying to validate my registration form. I'm using djanga-registration, it already has password
I'm doing a pretty simple validation that checks if two fields are equal. Unfortunately,
I have been trying to validate my web page for the last two hours,
When trying to validate my site, I get the following error: Line 188, column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.