This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes JS code not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JS code not working." Watch "JS code not working." New topic
Author

JS code not working.

pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi,
Could you please tell me where exactly I have made mistakes as the following JS code is not working.



Thanks,
Pramod
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61447
    
  67

Without giving us any idea where the problem is happening? Or even what the problem is? Please put a little more effort into your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hi Bear,

The code looks good to me, but neither the alert message nor the calculation part takes place if I run it.
Don't know what exactly went wrong.

Apologies for the inconvenience.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9466
    
    2

I'm not an expert in this. Try by putting the semicolon inside the double quotes instead of it being outside like you have mentioned in your post onchange="calculatePrice()";


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Nope Joe.
No change.
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
Your code contains numerous errors. I've spotted only two of them but I'm sure that there are more. For example, the following code

should be

Also, the following code

should be


Like Bear Bibeault said please put a little more effort into your post.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42355
    
  64
If you use Firefox, then the Error Console (to be found in the Tools menu) will be very valuable for tracking down JavaScript bugs.


Ping & DNS - my free Android networking tools app
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Hello,

I've corrected the code and it works fine now.

The only problem I'm facing right now is that if I leave "Name" or "minutesPickup" field empty or invalid, I do get Alert box but then the pointer moves to the next field.
I need to show the pointer in the same field after clicking OK on my Alert box.
I tried changing "onblur" to "onchange" for "Name" field but it didn't work.

Below is the code :
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
replace this code


with this
pramod talekar
Ranch Hand

Joined: Apr 26, 2010
Posts: 323

Thanks Ogeh Ikem
I tried out with both Name.focus() &document.getElementById("Name").focus();
Both ways, it works fine.
Ogeh Ikem
Ranch Hand

Joined: May 13, 2002
Posts: 180
You're welcome.
 
jQuery in Action, 2nd edition
 
subject: JS code not working.