473,396 Members | 1,998 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,396 software developers and data experts.

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\deliveries (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 1344
br*********@yahoo.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\deliveries (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.selectedIndex].text;
var destination = secondMenu[secondMenu.selectedIndex].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 getShippingMethod () {
var firstMenu = document.forms[0].elements[0];
var secondMenu = document.forms[0].elements[1];
if (firstMenu.selectedIndex != 0 && secondMenu.selectedIndex !=0) {
// console.warn(1);
var from = firstMenu[firstMenu.selectedIndex].text;
var destination = secondMenu[secondMenu.selectedIndex].text;
var msg = sendFromTo[from][destination];
//alert(msg);
document.getElementById('youChose').innerHTML = msg;
}
}
</script>

<form>
Ship From:
<select onchange="getShippingMethod()">
<option>Select a state</option>
<option>Alaska</option>
<option>Alabama</option>
</select>
<br>
Send To:
<select onchange="getShippingMethod()">
<option>Select a state</option>
<option>Alaska</option>
<option>Alabama</option>
</select>
</form>

<div>Send by method: <span id="youChose">No 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...@yahoo.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\deliveries (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.selectedIndex].text;
var destination = secondMenu[secondMenu.selectedIndex].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_with_2_s...
Hope this helps.

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

}function getShippingMethod () {
var firstMenu = document.forms[0].elements[0];
var secondMenu = document.forms[0].elements[1];
if (firstMenu.selectedIndex != 0 && secondMenu.selectedIndex !=0) {
// console.warn(1);
var from = firstMenu[firstMenu.selectedIndex].text;
var destination = secondMenu[secondMenu.selectedIndex].text;
var msg = sendFromTo[from][destination];
//alert(msg);
document.getElementById('youChose').innerHTML = msg;
}}</script>

<form>
Ship From:
<select onchange="getShippingMethod()">
<option>Select a state</option>
<option>Alaska</option>
<option>Alabama</option>
</select>
<br>
Send To:
<select onchange="getShippingMethod()">
<option>Select a state</option>
<option>Alaska</option>
<option>Alabama</option>
</select>
</form>

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

br*********@yahoo.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...@yahoo.comwrote:
bravespl...@yahoo.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*********@yahoo.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.javascript 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...@yahoo.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.javascript FAQ -http://jibbering.com/faq
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
Nov 8 '06 #7

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

Similar topics

2
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,...
1
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 {...
5
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 ...
44
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...
60
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....
7
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...
8
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
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? ...
4
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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.