Click to See Complete Forum and Search --> : urgent help ....


sexybee
03-08-2003, 08:12 PM
hello i need some help to do this convertion for this form. it so complicated i have no idea how or where to start, how many funcitons i need..please help me

http://www.catcode.com/cit041j/prog3.html


if the English field changes convert the English to Matrix and remember "my starting point is English"

if the Metrix field changes convert the Metrix to English and remember starting point is Metrix

if drop down menu changes convert from your starting point field ot the other one

AdamBrill
03-08-2003, 11:17 PM
Well, I took the example and looked at it for a minute... I think you should do something like this:
In the head, put a <script> tag. The first thing that should be done is declaring a variable at the top. Like this:

var whichone="";

The convert function(called by the onchange) should then be added into the script. Here is what I did:
var whichone="";
function convert(whichway)
{
if(whichway)
{
whichone=whichway;
}else{
if(whichone=="english")
{
english(document.convertForm.menu.selectedIndex);
}else{
metric(document.convertForm.menu.selectedIndex);
}
}
}
Now, let me explain. :) The first if command checks if you returned anything when you called the function. If they did, then it sets the whichone variable to be what they returned. This makes the onchange work on the input fields. The else handles when the onchange is triggered by the <select>. When that is run, it will check if whichone is set to english or metric. If it is set to english, then it runs the english function; if it is set to metric it runs the metric function, both of which you have to make. So, create both of those functions and put them after the convert function. Then, you can check which option the select is on using something like this:
if(selectedone==1)
{
//The Fahrenheit <- -> Celsius option
}
if(selectedone==2)
{
//The miles <- -> kilometers option
}
So, that is pretty much how it will be done. Then, you will have to make the english one to convert to metric and the metric one to convert to english. Let me know if you have any more problems or questions... :)

khalidali63
03-09-2003, 09:16 AM
How about this page,check it out.

http://68.145.35.86/skills/javascripts/ConversionsUtility.html

Cheers

Khalid

sexybee
03-09-2003, 05:10 PM
thanks adam and khali for helping me..ummm i still have some problem. adam, i followed your steps and i wrote 2 functions enlgish to matrix and matrix to english then now i got a big mess. can u see what wrong with my codes and guide me through the mess i've made.



:confused: :confused: :mad: :confused:
function huh(totally confused)
document.write( ":confused: Lost, confused and disoriented..i need help badly" );
alert( "HELP!!" );

AdamBrill
03-09-2003, 05:21 PM
Ok, try this. Put this script inside of your head:
<script language=javascript>
whichone="";
function convert(which)
{
if(which)
{
//if they returned anything when they called the function
whichone=which;
}else{
if(whichone=="english")
{
//if they returned "english"
english(document.convertForm.menu.selectedIndex);
}else{
//if they returned "metric"
metric(document.convertForm.menu.selectedIndex);
}
}
}
function english(selectedone)
{
//convert from english to metric
TheValue=document.convertForm.english.value;
if(selectedone==1)
{
//if they selected Fahrenheit <- -> Celsius
F=TheValue;
C =((F - 32) / 9) * 5;
document.convertForm.metric.value=C;
}
if(selectedone==2)
{
//if they selected miles <- -> kilometers
miles=TheValue;
km = miles * 1.609344;
document.convertForm.metric.value=km;
}
if(selectedone==3)
{
//if they selected pounds <- -> kilograms
pounds=TheValue;
kg = pounds * 0.4536;
document.convertForm.metric.value=kg;
}
if(selectedone==4)
{
// if they selected miles per gallon <- -> km per liter
mpg=TheValue;
kpl = mpg * 1.609344 / 3.785;
document.convertForm.metric.value=kpl;
}
}
function metric(selectedone)
{
//convert from metric to english
TheValue=document.convertForm.metric.value;
if(selectedone==1)
{
//if they selected Fahrenheit <- -> Celsius
C=TheValue;
F = ((C / 5) * 9) + 32;
document.convertForm.english.value=F;
}
if(selectedone==2)
{
//if they selected miles <- -> kilometers
km=TheValue;
miles = km * 0.62137;
document.convertForm.english.value=miles;
}
if(selectedone==3)
{
//if they selected pounds <- -> kilograms
kg=TheValue;
pounds = kg * 2.2046;
document.convertForm.english.value=pounds;
}
if(selectedone==4)
{
// if they selected miles per gallon <- -> km per liter
kpl=TheValue;
mpg = kpl * 0.62137 * 3.785;
document.convertForm.english.value=mpg;
}
}
</script>Is this for some sort of assignment? If so, look at the comments to see what is going on. Let me know if you have any questions. :)

sexybee
03-09-2003, 05:23 PM
oops for got the codes
===============================
<script type="text/javascript">
// <![CDATA[
var whichone="";
function convert(whichway)
{
if(whichway)
{
whichone=whichway;
}else{
if(whichone=="english")
{
english(document.convertForm.menu.selectedIndex);
}else{
metric(document.convertForm.menu.selectedIndex);
}
}
}




function e2m( )
{
var chosen;
var theMenu;
var optionValue;

theMenu = document.convertForm.conversionList;
chosen = theMenu.selectedIndex;

if(selectedone==1)
{
//The Fahrenheit - - Celsius option
var C;
C = ((F - 32) / 9) * 5;
}
if(selectedone==2)
{
//The miles - - kilometers option
var km;
km = miles * 1.609344;
}
if(selectedone==3)
{
//pounds - - kilograms
var kg;
kg = pounds * 0.4536;
}
if(selectedone==4)
{
//miles per gallon - - km per liter option
var kpl;
kpl = mpg * 1.609344 / 3.785;
}
}



function m2e( )
{
var chosen;
var theMenu;
var optionValue;

theMenu = document.convertForm.conversionList;
chosen = theMenu.selectedIndex;

if(selectedone==1)
{
//Celsius - - Fahrenheit
var F;
F = ((C / 5) * 9) + 32;
}
if(selectedone==2)
{
//kilometers option - - miles
var miles;
miles = km * 0.62137;
}
if(selectedone==3)
{
//kilograms - - pounds
var pounds;
pounds = kg * 2.2046;
}
if(selectedone==4)
{
//km per liter option - - miles per gallon
var mpg;
mpg = kpl * 0.62137 * 3.785;
}
}

// ]]>
</script>

khalidali63
03-09-2003, 05:25 PM
Originally posted by AdamBrill
...... Put this script inside of your head:
.........

LoL..Adam
:p
Cheers

Khalid

AdamBrill
03-09-2003, 05:34 PM
oops... :D Put the script in THE head... ;) Does that sound better? :cool:

sexybee - I don't think you saw my code. Try taking a look at it and let me know if you have any more questions... :)

sexybee
03-09-2003, 06:15 PM
LOL..adam....i have a good laugh as u said put in my head..i think i will if there is still room indside my head :D

oh yeah it assignment for my javascript class..man programming is tough. it fried my brain.i sit in the class all i heard from the instructor was blah blah blah and my head like on fire..i go home open the book 3 inches thick and weight a ton try to skim through it and almost go blind..lol

im trying your codes right now...later ;)

AdamBrill
03-09-2003, 06:23 PM
Originally posted by sexybee
oh yeah it assignment for my javascript class..man programming is tough. it fried my brain.i sit in the class all i heard from the instructor was blah blah blah and my head like on fire..i go home open the book 3 inches thick and weight a ton try to skim through it and almost go blind..lol LOL :) I picked up programming pretty easy, so that wasn't really a problem for me. I do, however, have plenty of thick books. My stack(if I put them all in a stack...;)) is about 3 or 4 feet high. :D My thickest one has almost 1500 pages... :cool:

sexybee
03-09-2003, 06:27 PM
hi its me again..lol

umm...when i try the codes its said something like "document.convertForm.menu.selectedIndex is null or not an object"
whats going on??whats the heck is that??:confused:

AdamBrill
03-09-2003, 06:40 PM
hmm... It shouldn't have done that. :) Try the attached code and let me know if it works. Just rename the file from Works.txt to Works.htm and it should work. Let me know if you have any more problems... ;)

sexybee
03-09-2003, 07:34 PM
the code i said was giving me some error message its was my fault..im not only dump like a duck but very sloppy as well i got the name wrong in the select field i fixed it and it works perfect:D

umm..i just wondering is posible to like for example when i put in the 0 in the metric field then i select convert F to C it will put the 32 in the English field then if i enter a new number for example 100 then i just click outside the field and it detects the change had been made and do a new convertion automaticly without i have select a different option then select it again in order for it to work and vice versa:rolleyes:

AdamBrill
03-09-2003, 07:44 PM
hmm... I'm not exactly sure how you would want that to work, but try this and let me know what you think. ;)

sexybee
03-09-2003, 09:46 PM
omg... yesssss! :p u r the best. now i can hop around like a happy bunny....thank you very much..can i buy u lunch :)

AdamBrill
03-09-2003, 10:14 PM
Originally posted by sexybee
omg... yesssss! u r the best. now i can hop around like a happy bunny....thank you very much..can i buy u lunchhmm... Where do you live? :D If your ever coming through upper Wisconsin... I must warn you, however, that it is mighty cold up here. ;) The wind chill is -15 right now. :eek: Anyway, I'm glad I could help. :)

sexybee
03-10-2003, 11:30 AM
im in california...sunny and warm for most of the time ;)...will drop u a notes when i stop by Wisconsin :)...where is it anyway ..lol

thanks again for your help,

AdamBrill
03-10-2003, 12:33 PM
Originally posted by sexybee
im in california...sunny and warm for most of the time ;)Sure... Brag about it... :D BTW, to find Wisconsin, look at Canada and then go down just a hair. That's Wisconsin. :p