473,587 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate form values based on previous same form fields

This message is cross posted in
alt.comp.lang.p hp & comp.lang.javas cript

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 4989
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=func tion(a,b){
return this>=Math.min( a,b) && this<=Math.max( a,b);
}

if(!( +event_start < +event_end &&
+event_start.is Between(+store_ open,+store_clo se) &&
+event_stop.isB etween(+store_o pen,+store_clos e))){
alert ("NO")
}
Mick
Jul 23 '05 #2
"Rizyak" <ry**********@l atitude47.comAN DMETOO> wrote in message news:<ca******* ***@nntp1.u.was hington.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.val ue == "" )
{
alert("Enter a store open time.");
inputOK= false;
}
else if( x.storeClose.va lue == "" )
{
alert("Enter a store close time.");
inputOK= false;
}
else if( x.eventStart.va lue == "" )
{
alert("Enter an event start time.");
inputOK= false;
}
else if( x.eventEnd.valu e == "" )
{
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.s toreOpen.value) ;
var storeClose = convertTime(x.s toreClose.value );
var eventStart = convertTime(x.e ventStart.value );
var eventEnd = convertTime(x.e ventEnd.value);

alert(".storeOp en.value = " + x.storeOpen.val ue +
" storeOpen = " + storeOpen +
"\n .storeClose.val ue = " + x.storeClose.va lue +
" storeClose = " + storeClose +
"\n .eventStart.val ue = " + x.eventStart.va lue +
" eventStart = " + eventStart +
"\n .eventEnd.value = " + x.eventEnd.valu e +
" eventEnd = " + eventEnd );

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

// ............... ............... .......
function convertTime(tim eString)
{

//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(timeSt ring,10) * 60;

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

var minutesIndex = timeString.inde xOf(":");
if ( minutesIndex >= 0 )
{
var minutes = timeString.subs tr(minutesIndex +1);
theTime += parseInt(minute s,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.notavalidwe baddress.com"
method="POST"
onSubmit="retur n validateAll();" >

<p>Store start time:<br>
<input type="text" name="storeOpen " size="20"><br>< br>
Store end time:<br>
<input type="text" name="storeClos e" size="20"><br>
</p>
<p>The little event times.</p>
<p>Event start time:<br>
<input type="text" name="eventStar t" 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.javas cript

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.co m...
Rizyak said:

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

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
5366
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 Pen ABC & Co. Boston
11
18823
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 they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion...
1
2218
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. When a user chooses an option from the item drop down, the price, delivery, availability will then populate. I have already made my connection to...
1
3388
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. The user would enter the two criteria in the form and the ten fields autopopulate. To achieve this, I used a Dlookup function in the Control Source...
3
3611
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 computer components and peripherals (i.e networking devices, hard drives etc etc), the previous mentioned devices are in a table called product...
5
17673
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. The species list has 7 fields the first is a four digit unique identifier (species) it is set as the primary key. I have created a relationship to...
0
1262
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 on the form based off the job selection. The only thing I could come up with is this If .Value = "EZ0032" Then + 4 ElseIf .Value = "EZ0840"...
4
13948
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 tbl_Input has three fields: OSE_Job, OSE_Name, OSE_Wt I have populated tbl_OSE_Info table. I need to create a form that will store the data in...
5
3990
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 Fields Names: countrycode, make
0
7923
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8221
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.