Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

set focus using js file

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
i have 2 text box in my form (FirstName, and LastName) . When the value of one text box changes i call genericValidation on onchange event.



In the above code which is in js file, how i can set the focus to LastName.

thnx is advance
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
N Chaurasia,

Use focus() on textbox object, like

document.<formname>.<lastname textboxname>.focus(). If you have "id' defined for lastname textbox, then you can also focus that element like,

document.getElementById(" <lastname textbox id>").focus();
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pavan i tried it but it is not working
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To set an object properties for common using you may pass an object reference. May be you should change the argument of your js function like this :

argObj --> the text field object ie. FirstName/LastName
objValue --> some value entered on that field

function genericValidation(argObj, objValue)
{

//set focus
argObj.focus();
return true;
}

your HTML code may look like this :

<form name="someForm">
<input type="text" name="FirstName" value="" onchange="genericValidation(document.someForm.LastName, this.value)">
<input type="text" name="LastName" value="">
</form>

Correct me if i'm wrong. thanks.

Rgds,
Wyasa
 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wayan , i tried above code...it does not help
 
Pavan Keely
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
N Chaurasia,

Can you please post the code that you are trying to use with the HTML used for last name and firstname text boxes.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I suspect you are using IE( = BUGGY ).

First of all, for more ensured selection, you need to invoke both the
focus() and select() methods for your text field. Second, you need to create an artifical delay before trying to set focus to your control.

Try something like this:



You need to pass the element id instead of a reference to the element in the function above, but you could rewrite it to take an object reference if you wanted to.

Hope this helps,
Regards,
Roy

[ July 11, 2006: Message edited by: Roy Ivar Moe ]
[ July 11, 2006: Message edited by: Roy Ivar Moe ]
 
Wayan Suwastika
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I try to figure out your problem. It seem the onChange event will only fired when an object is lost focus or onLostFocus or onBlur event was fired.
May be you sould change the way you move the focus with call the
onKeyUp event on your Text field object. This event will call when a keyboad key is up (release) and its mean the content was of your text field was changed.
The HTML code may look like this:


pls replace space at o n K e y U p word.

Rgds,
Wyasa
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic