It is currently Sat Oct 25, 2014 2:04 am

All times are UTC + 2 hours [ DST ]

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: javascript newbie: firefox - select()/focus() not working
PostPosted: Wed Jan 09, 2008 12:00 pm 

Joined: Wed Jan 09, 2008 11:36 am
Posts: 6
Hi guys,

I am new to javascript and am currently learning it with the book Wrox Beginning Javascript 3rd ed.

I have just encountered a problem that I am not able to figure out. Could you please help me out.....

The problem is that select() and focus() are not working in FF2.0 but works in IE7.

This is what the code is supposed to do:
1. I enter a age
2. If I enter non numerical data and then I tab out of the text area
3. An alert box pops up and tells me to correct the age.
4. On hitting ok it goes back to the age field.

But in FF its going to the next tag(the submit button).

This is the code:

<script type="text/javascript">

function txt_age_onblur()
   var in_txt_age = document.form1.txt_age;

   if (isNaN(in_txt_age.value))
      alert("Please enter a valid age");
      [b]in_txt_age.focus();        //looks as if no need for focus() as I am able to edit the text with only select()  in IE. Not working with FF.;        //Not working with FF[/b]
<form name=form1>
   <input type=text name=txt_age onblur="txt_age_onblur()" size=3 maxlength=3 />
   <input type=button value=Submit />

Thanks for you time friends. :-)..............

 Post subject:
PostPosted: Sat Jan 12, 2008 10:44 pm 

Joined: Sun May 02, 2004 11:34 pm
Posts: 6611
Location: toronto, canada ... focus.html suggests using the below code to set the focus in FF since there is a timing issue in how the events fire



Cat, the other other white meat

Please read Posting Etiquette before posting

You can always try Google

 Post subject:
PostPosted: Sun Jan 13, 2008 3:15 am 

Joined: Wed Jan 09, 2008 11:36 am
Posts: 6
Hi Lostboy,

Thanks a lot. :-)...................................................

The code is now working!!!!!!!!!!

I also found that the code works fine with just the select() command. Because when we invoke select, the foucs is automatically on that cell and we can edit the text immediately. Then why are we using a separate focus() command. It seems unnecessary.

Thanks for your time.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 2 hours [ DST ]

Who is online

Users browsing this forum: No registered users and 0 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to: