my 'if' comands are still not working. please help

G

Guest

function showorders() {

alert("start of show orders script");

var form = document.forms.favororders;

alert("123456789");
if (document.form.Avocado.value) {
document.write("avo>0");
}

alert("after the first if in show orders script");
if (form.ButterSquash.value) {
document.write("but>0");
}
}



the first line up to and including alert("123456789") work ok.
the rest does not to execute.
again i can not seem to understand how the 'if' and 'form' commands work, i
have gone to the library to look at a few javascript books, still none the
wiser.

i have also used this line inplace of the one similar above.

if (eval(parent.orderpageiframe.form.Avocado.value)) {

with the same results, there is something wrong with the 'if' lines.
each 'if' command work independatly from each other.
there are not if, else, else, else.
there are

if this then do that;
new query...
if something then do something else;
...
....


thanks

Jason
 
D

deprez

Hello Jason,
First off I would suggest you type "javascript:" in your mozilla
browser.
This will give you the errors you are making.
It seems that you are having a problem accessing your form variable.
Good Luck,
Geodepe
http://www.digitalorder.com
 
D

deprez

Here is how I would do it...
----------------------------------- SNIP
---------------------------------------
<html>
<head>
<script>
function showorders() {

alert("start of show orders script");

var form = document.favororders;

alert("123456789");
if (form.Avocado.value) {
document.write("avo>0");
}
else
{
document.write("avo<=0");
}
alert("after the first if in show orders script");
if (form.ButterSquash.value) {
document.write("but>0");
}
return 0;
}
</script>
<body>
Hello

<form name="favororders" id="favororders" action="do.jsp" method="get">
<input type="text" name="Avocado" value="1">
<input type="text" name="ButterSquash" value="1">
<input type="submit" value="Submit">
</form>


<script>
document.write("hello<br>");
showorders();
document.write("hello<br>");
</script>
</body>
</html>
-------------------------------------END
SNIP----------------------------------------
Hope this helps,
Geodepe
http://www.digitalorder.com
 
G

Guest

hi,

thanks

but i do not need the 'else' parts just the 'if' like below.
how do i use loads of 'if' but NOT have them nested 'if's

the file is not a htm, html file it is a .js file that is called from a
htm file that has
<script language="javascript" src="showorders.js"></script>
in the head part.





if (condition you selected apples) {
document.write("apples="+cost);
}

if (condition you selected pears) {
documents.write("pears="+cost);
}

....
....
....
....

if (condition you selected oranges) {
documents.write("oranges="+cost);
}
 
G

Guest

yes I think it is still the form I am having problems with.

please can you suggest a way to fix this?


below is the .js file
I can access the form from another .js script with no problems..


function showorders() {
form = document.forms.favororders;
alert("start of show orders script");
alert(form.Avocado.value);
}
 
M

MikeR

if (document.form.Avocado.value) {
document.write("avo>0");
}
evaluates the if as a boolean (true or false). What are your possible values?

If the condition is NOT true, then the action will be as you report. The else
clause covers that possibility. If the action were true, then your write
statements would display. Despite how you WANT it to work, it follows the rules of
logic as defined by the language.
Why the condition isn't true is another issue.
 
G

Guest

if i put it this way, as i have tried to explain exactly what i want to do
but not got very far.
the more i ask the more i find better ways to explain.

i have an order page mostly written in javascript. (it's been fun)

not this part though.
the IF statement and using the information from the form in one iframe in
another iframe for processing, so it shows the orders made. (the posting of
the orders is not an issue here, it is sent to a file on the sever.)

i have added alert("alert1") with the number changed every time i use it.
to see what is happening.

first i think i need to get the form issue sorted.

is there a site that is just about forms, and how to access the data within
forms while in another frame.

the document......
and parent......
commands are really confusing, in the way it is used. i need to find how to
use these correctly.

i have:

function showorders() {
alert("start of show orders script");
form = document.forms.favororders;
document.write(form.Avocado.value);
alert("end of show orders script");
}


but the only line that work is the first alert, the rest is not working, or
executed.

i have checked the spellings and the case of the letters, all are correct.

omiting the document.write.... line the script run from start to finish
showing both alerts.

what is the correct syntax for this line?


thanks

Jason
 
M

MikeR

Jason -
Sorry, but you're over my head. I don't know how to handle those objects. Good luck.
MikrR
 
G

geodepe

No, you don't need the "else" parts. I added them to help in
understanding.

Regarding the "loads of if statements", there is the "switch" statement
you may be interested in using:

example:
switch(mycondition)
{
case "apple":
do_something;
break;
case "orange":
do_somethingelse;
break;
case "pear":
do_still_somethingelse;
break;
default:
do_something_if_none_of_them_match;
break;
}

Only one case will execute.

The rules of javascript should be the same wether the code is internal
or external.

Did you try the code I supplied?

Please supply more code if you need debugging help.

Also, what are you using to process the form?
Typically, you would need CGI,PERL,JSP,PHP,etc.
You may want to set up a session and maintain a "shopping cart".
Anyway that is my recommendation.

Regards,
Geodepe
http://www.digitalorder.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top