homepage Welcome to WebmasterWorld Guest from 50.19.169.37
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript and Forms
'Object Expected'
PitMonkee




msg:1486961
 10:29 pm on Apr 18, 2002 (gmt 0)

I'm working on a Javascript that checks to see which options are selected, and then displays a price in a div tag. When I click any option, it gives me an error. I click to see what the error is, it says this:
Line: 70
Char: 2
Error: Object Expected
Code: 0
URL: file://C:\Documents and Settings\Josh\Desktop\New Site\stepOne.htm

Can anyone tell me what it is without seeing the actual javascript and html? If you need to, I can give ya a link to check it out. Thanks!

Josh

 

jatar_k




msg:1486962
 10:45 pm on Apr 18, 2002 (gmt 0)

it sounds like a syntax error to me but you could post the offending line or so and we could give it a go.

PitMonkee




msg:1486963
 10:48 pm on Apr 18, 2002 (gmt 0)

ummm...I'm actually not sure where the offending line is...It's saying that the error is actually in the htm page, and I can't figure out how that can be. There's only like 10 lines or so in the javascript, and it's saying that the error is on line 70. That's why I'm clueless.

Josh

jatar_k




msg:1486964
 10:50 pm on Apr 18, 2002 (gmt 0)

interesting, stickmail me the url

PitMonkee




msg:1486965
 10:55 pm on Apr 18, 2002 (gmt 0)

You've got StickyMail!

Josh

jatar_k




msg:1486966
 10:58 pm on Apr 18, 2002 (gmt 0)

here is where the error is

illegal document.domain value com.com.
JavaScript Error: www.thedomain.com/order.js,
line 7:

missing ; before statement.

} elseif ((document.orderForm.model.F3) (document.orderForm.model.F4)) {

netscape javascript debugging is awesome

PitMonkee




msg:1486967
 11:01 pm on Apr 18, 2002 (gmt 0)

I'm not seeing it...Is there supposed to be a ; on line 7? I looked at 6, because most debuggers I've seen give the line below where the ; should go...but 6 has its ;

Josh

jatar_k




msg:1486968
 11:14 pm on Apr 18, 2002 (gmt 0)

try this code

function changePrice() {
var totalPrice;
totalPrice = 0;

if ((document.orderForm.model.F1) ¦¦ (document.orderForm.model.F2)) {
totalPrice = 225;
} else {
if ((document.orderForm.model.F3) ¦¦ (document.orderForm.model.F4)) {
totalPrice = 250;
} else {
if ((document.orderForm.model.F1) ¦¦ (document.orderForm.model.F6)) totalPrice = 275;
}
}

if ((document.orderForm.handles[1].checked) ¦¦ (document.orderForm.handles[2].checked)) {
totalPrice += 50;
} else {
if (document.orderForm.handles[3].checked) totalPrice += 150;
}

if (document.orderForm.blade[1].checked) totalPrice += 150;

if ((document.orderForm.bolsters[2].checked) ¦¦ (document.orderForm.bolsters[3].checked)) {
totalPrice += 75;
} else {
if (document.orderForm.bolsters[1].checked) totalPrice += 30;
}

if (document.orderForm.fileWork.checked == true) {
totalPrice += 50;
}

document.subTotal.innerHTML = "$" + totalPrice;

PitMonkee




msg:1486969
 11:18 pm on Apr 18, 2002 (gmt 0)

Hmm... Still gives me the same error.

Josh

jatar_k




msg:1486970
 11:29 pm on Apr 18, 2002 (gmt 0)

sorry i screwed up

function changePrice() {
var totalPrice;
totalPrice = 0;

if ((document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F1') ¦¦ (document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F2')) {
totalPrice = 225;
} elseif ((document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F3') ¦¦ (document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F4')) {
totalPrice = 250;
} elseif ((document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F5') ¦¦ (document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F6')) {
totalPrice = 275;
}

if ((document.orderForm.handles[1].checked) ¦¦ (document.orderForm.handles[2].checked)) {
totalPrice += 50;
} elseif (document.orderForm.handles[3].checked) {
totalPrice += 150;
}

if (document.orderForm.blade[1].checked) {
totalPrice += 150;
}

if ((document.orderForm.bolsters[2].checked) ¦¦ (document.orderForm.bolsters[3].checked)) {
totalPrice += 75;
} elseif (document.orderForm.bolsters[1].checked) {
totalPrice += 30;
}

if (document.orderForm.fileWork.checked == true) {
totalPrice += 50;
}

document.subTotal.innerHTML = "$" + totalPrice;

i think this will do it, it is the way you get the value from your drop down you have to do

document.orderForm.model[document.orderForm.model.selectedIndex].value == 'Model F1'

PitMonkee




msg:1486971
 11:36 pm on Apr 18, 2002 (gmt 0)

Thanks for the script...but now I'm certain that it's not the javascript, because no matter what is done to the javascript, it still gives me the exact same error. Is there something wrong with my onClick="changePrice();" ?

Josh

jatar_k




msg:1486972
 6:21 am on Apr 19, 2002 (gmt 0)

seems foolish but did you try

onClick="javascript:changePrice();"

I wouldn't think this is the problem though because it actually went to the function given that the error it gives is in the function.

Iguana




msg:1486973
 7:44 am on Apr 19, 2002 (gmt 0)

When things get really confusing with Javascript errors, check that objects on the page are really there. It may be your problem

If the <SCRIPT> is in the BODY rather than the HEAD then the DIV may not have been created yet and you will get a Object exepected error.

PitMonkee




msg:1486974
 12:37 pm on Apr 19, 2002 (gmt 0)

No matter what I do, I still can't get it to work...I've tried all of your suggestions, and it still gives me the same thing. I have no idea what's going on!

Josh

joshie76




msg:1486975
 1:19 pm on Apr 19, 2002 (gmt 0)

Hi PitMonkee,

Are you still struggling with this? If you are, Sticky me the URL and I'll have a look.

PitMonkee




msg:1486976
 4:25 pm on Apr 19, 2002 (gmt 0)

Yes, I'm still struggling...I got the error to go away by getting rid of the elseifs and making them seperate if statements...although it's really not the way I wanted it. Now I can't get it to recognize a div that I want to display something in. I'll sticky the URL to ya.

Josh

MikeFoster




msg:1486977
 6:27 pm on Apr 19, 2002 (gmt 0)

Did you solve this?

jatar_k's code looks ok except that "elseif" is not one word, its two words...

if (...) {
}
else if (...) {
}
else {
}

jatar_k




msg:1486978
 6:30 pm on Apr 19, 2002 (gmt 0)

yeah sorry about that, spent some time this morning kicking myself but wasn't near a cpu. Fixed it the first time and then messed it up again.

joshie76




msg:1486979
 6:40 pm on Apr 19, 2002 (gmt 0)

The first error I came across is how the include file (.js) changes the sub-total.

The sub total is a div tag with a name="subTotal" attribute. The script then tries to change the innerHTML of the div tag like follows:

document.orderForm.subTotal.innerHTML = totalPrice

The blue bit is the problem. The 'orderForm' (<form name="orderform">) collection only contains true form elements for scripting purposes - so input tags and textareas are pretty much all you get to through the form itself.

This is easily fixed by giving your div tag an id="subTotal" attribute.

document.getElementById('subTotal').innerHTML = totalPrice

However this might not be the best solution. You may be better to make the subtotal div a real form input. This way it will reset correctly when somebody clicks the reset button and it will also be more cross-browser friendly as not all browsers can handle the innerHTML property change (nn4 and possibly Opera).

Finally your <SELECT name=model> needs a onchange="changePrice()" attribute and your script should be all ok.

Let me know if you get it working... best of luck

Josh

PitMonkee




msg:1486980
 8:53 pm on Apr 19, 2002 (gmt 0)

Woohoo! It's finally working! Thanks everybody for all of your help...Don't know what I woulda done without ya. Thanks, jatar_k for everything you did, and thanks for fixing the else if problem for me, Mike. Also, thanks for the help on the getElementById, Josh. I knew I needed to put on onChange="changePrice();" in the select, but I never got around to it because the script wasn't working, so I saw no point at the moment. Also, I'm going to put an onClick in the reset button so that it will automatically reset to the original price when the form is reset. Only thing I have left to do is write a little script to change the picture to the right of the select menu so that it changes when you change options in the select menu; that won't be difficult, because I did it once before when I originally did this site. Thanks again for all of your help! Although I'm sure ya'll will hear from me again soon (Problems just seem to find their way to my doorstep.) ^_^

Josh

PitMonkee




msg:1486981
 9:18 pm on Apr 19, 2002 (gmt 0)

Well, now I've got another question lol. I forgot that I have to make a couple of the radios disabled when a certain option in the select menu is selected. I tried this:
function modelChange() {

if (document.orderForm.model.selectedIndex == 4) {
for (loop= 1; loop < 4; loop++)
document.orderForm.handles[loop].disabled = true;
document.orderForm.handles[0].checked = true;
}
}

But it doesn't seem to do anything. That is exactly how I did it in the last script I did that did this, but it doesn't seem to work this time. What's going on? I'm clueless again ^_^

Josh

PitMonkee




msg:1486982
 9:26 pm on Apr 19, 2002 (gmt 0)

Hmmm...nevermind, It started working all of a sudden...Don't know what was going on. Computers can be quite finicky sometimes ^_^

Josh

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved