473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Populate form values based on previous same form fields

This message is cross posted in
alt.comp.lang.php & comp.lang.javascript

I have a form for a user to input an establishment's hours and what time an
event is taking place. After the user inputs their establishment's hours of
operation I want the form elements lower in the form to adjust so that an
event can only happen when the place is open.

I have two fields for the hours:
These are both select fields with values between 0-23
store_open
store_close

Later in the form I have
event_start
event_stop

These values need to be between whatever store_open and store_close are.

I am stuck.

Thank you.


Jul 23 '05 #1
4 4972
Rizyak wrote

I have two fields for the hours:
These are both select fields with values between 0-23
store_open
store_close

Later in the form I have
event_start
event_stop

These values need to be between whatever store_open and store_close are.

I am stuck.

Thank you.


One approach

Number.protoype.isBetween=function(a,b){
return this>=Math.min(a,b) && this<=Math.max(a,b);
}

if(!( +event_start < +event_end &&
+event_start.isBetween(+store_open,+store_close) &&
+event_stop.isBetween(+store_open,+store_close))){
alert ("NO")
}
Mick
Jul 23 '05 #2
"Rizyak" <ry**********@latitude47.comANDMETOO> wrote in message news:<ca**********@nntp1.u.washington.edu>...
I have a form for a user to input an establishment's hours and what time an
event is taking place. After the user inputs their establishment's hours of
operation I want the form elements lower in the form to adjust so that an
event can only happen when the place is open.


Here is one approach to validating the event times:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Verify time fields</title>

<script type="text/javascript">

// ------------------------------------------
function validateAll()
{
alert("in validateAll");

var x = document.forms["myForm"];
var inputOK;

if( x.storeOpen.value == "" )
{
alert("Enter a store open time.");
inputOK= false;
}
else if( x.storeClose.value == "" )
{
alert("Enter a store close time.");
inputOK= false;
}
else if( x.eventStart.value == "" )
{
alert("Enter an event start time.");
inputOK= false;
}
else if( x.eventEnd.value == "" )
{
alert("Enter an event stop time.");
inputOK= false;
}
else
{
inputOK = checkBoth();
}

alert("from validateAll. inputOK = " + inputOK);
return inputOK;

}

// ..............................
function checkBoth()
{
alert("In checkBoth...");

var x = document.forms["myForm"];

var inputOK;

// Convert the times in string format to numeric format
// in minutes.
var storeOpen = convertTime(x.storeOpen.value);
var storeClose = convertTime(x.storeClose.value);
var eventStart = convertTime(x.eventStart.value);
var eventEnd = convertTime(x.eventEnd.value);

alert(".storeOpen.value = " + x.storeOpen.value +
" storeOpen = " + storeOpen +
"\n .storeClose.value = " + x.storeClose.value +
" storeClose = " + storeClose +
"\n .eventStart.value = " + x.eventStart.value +
" eventStart = " + eventStart +
"\n .eventEnd.value = " + x.eventEnd.value +
" eventEnd = " + eventEnd );

if ( eventStart > eventEnd )
{
alert("Event start must be before " +
"or equal to event end.");
x.eventStart.focus();
inputOK = false;
}
else if ( !isBetween(eventStart,storeOpen,storeClose) )
{
alert("Event start must occur " +
"when the store is open.");
x.eventStart.focus();
inputOK = false;
}
else if ( !isBetween(eventEnd,storeOpen,storeClose) )
{
alert("Event end must occur " +
"when the store is open.");
x.eventEnd.focus();
inputOK = false;
}
else
{
inputOK = true;
}
return inputOK;
}

// .....................................
function convertTime(timeString)
{

//Convert to a minute based value.
//Input may either be in 24 hour format
// or am/pm format.
// Examples 8:00am, 8, 8:12, 14:30, 2:30pm, or 4:30P.M.

var theTime = parseInt(timeString,10) * 60;

if ( timeString.indexOf("p") >= 0 ||
timeString.indexOf("P") >= 0 )
{
theTime += 12*60;
}

var minutesIndex = timeString.indexOf(":");
if ( minutesIndex >= 0 )
{
var minutes = timeString.substr(minutesIndex+1);
theTime += parseInt(minutes,10);
}

return theTime;
}

// ......................................
function isBetween(test,a,b)
{
return test>=a && test<=b;
}
</script>
</head>

<body>

<p>Please try out our form.</p>

<form name="myForm"
action="http://www.notavalidwebaddress.com"
method="POST"
onSubmit="return validateAll();">

<p>Store start time:<br>
<input type="text" name="storeOpen" size="20"><br><br>
Store end time:<br>
<input type="text" name="storeClose" size="20"><br>
</p>
<p>The little event times.</p>
<p>Event start time:<br>
<input type="text" name="eventStart" size="40">
<p>Event end time<br>
<input type="text" name="eventEnd" size="40">
</p>

<p><input type="submit" border="0" value="Submit">
</form>

</body>
</html>

Robert
Jul 23 '05 #3
Lee
Rizyak said:

This message is cross posted in
alt.comp.lang.php & comp.lang.javascript

I have a form for a user to input an establishment's hours and what time an
event is taking place. After the user inputs their establishment's hours of
operation I want the form elements lower in the form to adjust so that an
event can only happen when the place is open.

I have two fields for the hours:
These are both select fields with values between 0-23
store_open
store_close

Later in the form I have
event_start
event_stop

These values need to be between whatever store_open and store_close are.


The two answers I've seen have been describing how to validate the
input values to make sure they're in the correct range. Is that
what you're asking about, or are you trying to change the choices
that are available in Select menus?

You might want to be more flexible than that, anyway.
One of my favorite establishments lists their hours as
11:30am to 2am, but periodically hosts an event that
starts at 11am.

Jul 23 '05 #4
Indeed Lee is correct.
I am trying to change choices.
Envision selecting a state and a list of cities come up. I won't need to
make a database call like this, but it is similar ideas. Parent child
relationships.
I have come up with a solution that uses refresh and then I ran into
problems with my other form elements going away. Then I stored them as
cookies and had focus issues on refresh then I decided there has got to be
an easier way. If possible I would like to stick with dhtml....
I think the flexibility that lee was talking about won't be a problem once
the solution is found.
Thanks!

"Lee" <RE**************@cox.net> wrote in message
news:ca********@drn.newsguy.com...
Rizyak said:

This message is cross posted in
alt.comp.lang.php & comp.lang.javascript

I have a form for a user to input an establishment's hours and what time anevent is taking place. After the user inputs their establishment's hours ofoperation I want the form elements lower in the form to adjust so that an
event can only happen when the place is open.

I have two fields for the hours:
These are both select fields with values between 0-23
store_open
store_close

Later in the form I have
event_start
event_stop

These values need to be between whatever store_open and store_close are.


The two answers I've seen have been describing how to validate the
input values to make sure they're in the correct range. Is that
what you're asking about, or are you trying to change the choices
that are available in Select menus?

You might want to be more flexible than that, anyway.
One of my favorite establishments lists their hours as
11:30am to 2am, but periodically hosts an event that
starts at 11am.

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chand | last post by:
Hello Everyboy I am creating a small scale db with following fields in the table and form for the data entry purpose. Product ID Product Name Manufacturer Location 101 ...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
1
by: Flanman | last post by:
I have an ASP web form that I want to populate fields based on the first field choice. Example I have 4 fields item, price, delivery, availability. I have all these items setup in an access table....
1
by: dmeyr | last post by:
Hello, I am new to Access and am having difficulty with a Dlookup function. I have a form that I wish to autopopulate 10 fields with values based on two criteria which are also fields on the form....
3
by: jacklindsay | last post by:
Hello smarter people than me I am creating a database for college, and have requested some help, but they are unable to help me. ( im obviously too eager) anyway, im creating a database on...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
0
by: SimpDogg | last post by:
Hey guys another Newbie here... I have a combobox(JobName) on my form tied to a table named (Jobs) with one field for all of the jobs in the comboxbox. I want to auto populate the Due Out Date...
4
by: whamo | last post by:
I have the need to populate a field based on the selection in a combo box. Starting out simple. (2) tables tbl_OSE_Info and tbl_Input; tbl_OSE_Info has three fields: Key, OSE_Name and OSE_Wt...
5
by: giandeo | last post by:
Hello Experts. Could you find a solution for this problem please! I have the following tables in Access Database Table Name: origin Fields Names: country, countrycode Table Name: make...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.