473,670 Members | 2,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A "How would you go about coding this" question.

I am hoping for a code example of how to do this, and hopefully it will

help me to see an easy way to code what seems to be a huge monster.

I need to create a form that has two pulldown menues (field names
Option1 and Option2). Each will house a list of the 50 U.S. States.
Users would then be able to choose two states, and get a listing for a
courier used for pickup\deliveri es (exp: My order is in Ohio, but I
need it delivered to Maine. Who do I use?)
I am not as familiar with code as I would like, but it seems I would
need something like this:
If option1 = this, and option2 = this, then the answer (field name
Result) = this
I know that looks stupid, but I am hoping to show you how I am
approching this in my head.
Any ideas on how you would approch this project would be great. If you
could offer a sample of code, I'm sure I could use it as a template for

other projects. My idea is that this is just standard IF this THEN that

coding, but I don't know the basics enough to create the code from
scratch.
Thanks for any time you can give.

Nov 6 '06 #1
6 1350
br*********@yah oo.com wrote:
I am hoping for a code example of how to do this, and hopefully it will

help me to see an easy way to code what seems to be a huge monster.

I need to create a form that has two pulldown menues (field names
Option1 and Option2). Each will house a list of the 50 U.S. States.
Users would then be able to choose two states, and get a listing for a
courier used for pickup\deliveri es (exp: My order is in Ohio, but I
need it delivered to Maine. Who do I use?)
You can build a lookup table object, using JavaScript object notation.
If you are familiar with hashes, you can also think of this table as a
2-dimensional hash.

var sendFromTo = {
Alaska : {
Alaska : "local mail",
Alabama : "FedEx"
},
Alabama: {
Alaska : "UPS",
Alabama : "pony express"
}
}

Here is an example lookup against this table:

sendFromTo["Alaska"]["Alabama"] //evaluates to "Fedex"
>
I am not as familiar with code as I would like, but it seems I would
need something like this:
If option1 = this, and option2 = this, then the answer (field name
Result) = this
If you use this technique, you don't need a conditional. Instead,
after the user has chosen one value from each menu, submit those two
values to the table, and then display the result.

var from = firstMenu[firstMenu.selec tedIndex].text;
var destination = secondMenu[secondMenu.sele ctedIndex].text;

var msg = sendFromTo[from][destination];
//now display the value of "msg" to the user

Here is the code of a brief, working example of this kind of solution.
You can see it in action at
http://onemorebug.com/meme.washer/co...ect_menus.html
Hope this helps.

<script type="text/javascript">
var sendFromTo = {
Alaska : {
Alaska : "local mail",
Alabama : "FedEx"
},
Alabama: {
Alaska : "UPS",
Alabama : "pony express"
}
}

function getShippingMeth od () {
var firstMenu = document.forms[0].elements[0];
var secondMenu = document.forms[0].elements[1];
if (firstMenu.sele ctedIndex != 0 && secondMenu.sele ctedIndex !=0) {
// console.warn(1) ;
var from = firstMenu[firstMenu.selec tedIndex].text;
var destination = secondMenu[secondMenu.sele ctedIndex].text;
var msg = sendFromTo[from][destination];
//alert(msg);
document.getEle mentById('youCh ose').innerHTML = msg;
}
}
</script>

<form>
Ship From:
<select onchange="getSh ippingMethod()" >
<option>Selec t a state</option>
<option>Alask a</option>
<option>Alabama </option>
</select>
<br>
Send To:
<select onchange="getSh ippingMethod()" >
<option>Selec t a state</option>
<option>Alask a</option>
<option>Alabama </option>
</select>
</form>

<div>Send by method: <span id="youChose">N o method selected</span></div>

Nov 6 '06 #2
WOW! Thanks so much. I appreciate you offering this examples. It makes
it so much easier when you can SEE it.

Have a great day, and thanks again for all your help.

On Nov 6, 12:40 pm, "Noah Sussman" <blink...@gmail .comwrote:
bravespl...@yah oo.com wrote:
I am hoping for a code example of how to do this, and hopefully it will
help me to see an easy way to code what seems to be a huge monster.
I need to create a form that has two pulldown menues (field names
Option1 and Option2). Each will house a list of the 50 U.S. States.
Users would then be able to choose two states, and get a listing for a
courier used for pickup\deliveri es (exp: My order is in Ohio, but I
need it delivered to Maine. Who do I use?)You can build a lookup table object, using JavaScript object notation.
If you are familiar with hashes, you can also think of this table as a
2-dimensional hash.

var sendFromTo = {
Alaska : {
Alaska : "local mail",
Alabama : "FedEx"
},
Alabama: {
Alaska : "UPS",
Alabama : "pony express"
}

}Here is an example lookup against this table:

sendFromTo["Alaska"]["Alabama"] //evaluates to "Fedex"
I am not as familiar with code as I would like, but it seems I would
need something like this:
If option1 = this, and option2 = this, then the answer (field name
Result) = thisIf you use this technique, you don't need a conditional. Instead,
after the user has chosen one value from each menu, submit those two
values to the table, and then display the result.

var from = firstMenu[firstMenu.selec tedIndex].text;
var destination = secondMenu[secondMenu.sele ctedIndex].text;

var msg = sendFromTo[from][destination];
//now display the value of "msg" to the user

Here is the code of a brief, working example of this kind of solution.
You can see it in action athttp://onemorebug.com/meme.washer/code_examples/choose_value_wi th_2_s...
Hope this helps.

<script type="text/javascript">
var sendFromTo = {
Alaska : {
Alaska : "local mail",
Alabama : "FedEx"
},
Alabama: {
Alaska : "UPS",
Alabama : "pony express"
}

}function getShippingMeth od () {
var firstMenu = document.forms[0].elements[0];
var secondMenu = document.forms[0].elements[1];
if (firstMenu.sele ctedIndex != 0 && secondMenu.sele ctedIndex !=0) {
// console.warn(1) ;
var from = firstMenu[firstMenu.selec tedIndex].text;
var destination = secondMenu[secondMenu.sele ctedIndex].text;
var msg = sendFromTo[from][destination];
//alert(msg);
document.getEle mentById('youCh ose').innerHTML = msg;
}}</script>

<form>
Ship From:
<select onchange="getSh ippingMethod()" >
<option>Selec t a state</option>
<option>Alask a</option>
<option>Alabama </option>
</select>
<br>
Send To:
<select onchange="getSh ippingMethod()" >
<option>Selec t a state</option>
<option>Alask a</option>
<option>Alabama </option>
</select>
</form>

<div>Send by method: <span id="youChose">N o method selected</span></div>
Nov 6 '06 #3
VK

br*********@yah oo.com wrote:
other projects. My idea is that this is just standard IF this THEN that
coding
It is if you always have one-to-one relations (say for a parsel from
California to New Jersy there is only one possible combo of carriers).
It is more complicated if you (may) have one-to-many relations (say for
the above mentioned parsel there are three possible combo different by
price and terms).

Please alaborate on that.

Nov 6 '06 #4
Its one-to-one, and your example will work perfectly. Could you give me
some idea of the complications with a one-to-many. I would assume I
will have to cross that bridge one day. Thanks again for the time.

On Nov 6, 12:58 pm, "VK" <schools_r...@y ahoo.comwrote:
bravespl...@yah oo.com wrote:
other projects. My idea is that this is just standard IF this THEN that
codingIt is if you always have one-to-one relations (say for a parsel from
California to New Jersy there is only one possible combo of carriers).
It is more complicated if you (may) have one-to-many relations (say for
the above mentioned parsel there are three possible combo different by
price and terms).

Please alaborate on that.
Nov 8 '06 #5
br*********@yah oo.com said the following on 11/8/2006 9:24 AM:
Its one-to-one, and your example will work perfectly. Could you give me
some idea of the complications with a one-to-many. I would assume I
will have to cross that bridge one day. Thanks again for the time.
One to many is not that difficult, it's just easier not to use a simple
array to do it. An array of arrays where the main array holds the state,
the child array holds the multiple shippers.

Not sure what you are working on but another potential problem you are
going to run into is shipping across a state line. If you wanted to ship
a 1 pound box from Mobile Alabama to Savannah Georgia, you would use a
shipper, all is fine. But if you want to ship that same 1 pound box from
Phenix City Alabama to Columbus Georgia then the scenario changes (both
are shipped from AL to GA). The difference is Phenix City to Columbus is
about 4 feet and a state line. Mobile to Savannah isn't that simple.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 8 '06 #6
Thanks for everything. I appreciate the time.

On Nov 8, 11:21 am, Randy Webb <HikksNotAtH... @aol.comwrote:
bravespl...@yah oo.com said the following on 11/8/2006 9:24 AM:
Its one-to-one, and your example will work perfectly. Could you give me
some idea of the complications with a one-to-many. I would assume I
will have to cross that bridge one day. Thanks again for the time.One to many is not that difficult, it's just easier not to use a simple
array to do it. An array of arrays where the main array holds the state,
the child array holds the multiple shippers.

Not sure what you are working on but another potential problem you are
going to run into is shipping across a state line. If you wanted to ship
a 1 pound box from Mobile Alabama to Savannah Georgia, you would use a
shipper, all is fine. But if you want to ship that same 1 pound box from
Phenix City Alabama to Columbus Georgia then the scenario changes (both
are shipped from AL to GA). The difference is Phenix City to Columbus is
about 4 feet and a state line. Mobile to Savannah isn't that simple.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ -http://jibbering.com/faq
Javascript Best Practices -http://www.JavascriptT oolbox.com/bestpractices/
Nov 8 '06 #7

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

Similar topics

2
1825
by: Lee Stewart | last post by:
Another question about writing PHP 5 extensions. What's the difference in PHP_MINIT() / PHP_MSHUTDOWN() and PHP_RINIT() / PHP_RSHUTDOWN()? When would a "per request" init be made? Thanks, Lee LeeStewart @ gmail.com
1
5663
by: Peter King | last post by:
if you assign multiple classes in order to keep your classes generic e.g ..classA { position.absolute; left:5 top:5 height:200 width:800 } ..classB { background-color: red} ..classC { background-color: green} <div id="div1" class="classA classB" ... but then want to dynamically assign a new class
5
4382
by: John Oliver | last post by:
I'd like the email produced by FormMail to show a specific From: address rather than postmaster@server.host.name Googling isn't helping me... not sure what to look for :-( -- * John Oliver http://www.john-oliver.net/ * * California gun owners - protect your rights and join the CRPA today! * * http://www.crpa.org/ * * San Diego shooters come to...
44
4188
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a good concept?
60
5023
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this. consistently may make the code easier to understand for someone else, etc. Using "this." makes it immediately clear, for example, that the variable being referred to is a member of the same class and is not declared in the method as a local variable. ...
7
2416
by: Brave | last post by:
I am hoping for a code example of how to do this, and hopefully it will help me to see an easy way to code what seems to be a huge monster. I need to create a form that has two pulldown menues (field names Option1 and Option2). Each will house a list of the 50 U.S. States. Users would then be able to choose two states, and get a listing for a courier used for pickup\deliveries (exp: My order is in Ohio, but I need it delivered to Maine....
8
1634
by: mdh | last post by:
May I ask this. Given the declaration: int myf( int, int); and a function pointer: (*fp)=int myf(int, int); where I am initializing fp to point at myf....or trying to..
1
1629
by: patelxxx | last post by:
How to display PERL coding "Results" on webpages? What I'm trying to do is to display the result of the following PERL code on to a webpage and its not working. What can I do? #!c:/Perl/bin/perl.exe use Net::Ping; use strict; use warnings; my $host="192.168.0.1"; # Real IP removed by MODERATOR
4
1359
by: Jake Barnes | last post by:
<FAQENTRY> Weird. I go to Google and search for "javascript faq". These are the top results: http://www.javascripter.net/faq/index.htm http://www.irt.org/script/script.htm http://www.jibbering.com/faq/ I've got what I assume is an FAQ question:
0
8468
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8814
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8660
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7415
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1792
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.