 |
Javascript How-To Ask your "How do I do this with Javascript?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

June 30th, 2008, 10:57 AM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
cursor disappearance problem
I have a form with a few fields. The cursor shows up on the respective field where I want to fill out the form. The problem is when I click outside of the field the cursor disappears. It only happens when I click in the area outside of any text field of the form.
Is there anyway to solve this problem ? It happens in both IE and FF
Thanks
|

June 30th, 2008, 02:30 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Show sample code??? Certainly doesn't happen on my <FORM>s.
|

July 1st, 2008, 08:49 PM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
It is a form with few text fields, say text field 1, and text field 2. If I click on any of the text field, I can see the cursor and can type in whatever I want. The problem is, I want that cursor to persist in one of the text field. For example, if I click outside of the text field the cursor disappears and it comes back when I click on the field area. I want that cursor not to disappear at all and it should show up in the selected text field area.
This happens even with the simplest of the forms with text field. If I create a sample form with two text fields and click outside the text area the cursor disappears. I don't want that to happen.
Any help will be greatly appreciated,
Thanks.
|

July 1st, 2008, 11:56 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
AHHH!!! You meant the TEXT cursor! I thought you meant any cursor at all. That is, any MOUSE POINTER at all.
Okay, you can do this.
Code:
<HTML><BODY onLoad="document.TheForm.username.focus()">
<FORM name=TheForm>
username <INPUT name=username onblur="this.form.address.focus()"><br>
address <INPUT name=address onblur="this.form.city.focus()"><br>
city <INPUT name=city onblur="this.form.state.focus()"><br>
state <INPUT name=state onblur="this.form.submitButton.focus()"><br>
<INPUT Type=submit name=submitButton value="Submit this info">
</FORM>
</BODY></HTML>
|

July 2nd, 2008, 09:10 AM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Thanks a bunch!!!
Now I can see the cursor switching from one text field to another, depending upon the sequence I am giving in "onblur". I still have a question: is there a way of persisting it to the same text area, unless clicked in other text field. I mean if I am in say text field 3, and I click outside of text field 3, it should focus on text field 3 and not to text field 2 or some other.
I understand that we are giving focus to other text fields but can we persist it to the same field ?
Thanks again.
|

July 2nd, 2008, 02:47 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Of course.
<TEXTAREA ... onblur="this.focus();"></TEXTAREA>
Just set the focus back to itself.
But now there's a major problem!
What about when the user is *DONE* with the textarea and really *DOES* want to move to the next field????
HINT: HE CAN'T!!!
Once you get to the text area, you would be trapped there.
Now...we *could* set it up so that if the <BODY> received focus, it would automatically go to the textarea. But is even that good enough???
You know, you really are doing something that most people don't bother worrying about. Computer users today are smart enough, for the most part, to know that if the cursor is not in a particular field, they can't type there. I really have to wonder if you are doing a lot of work for no purpose.
|

July 3rd, 2008, 09:09 AM
|
Authorized User
|
|
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
*smiles*
thanks again, really.
It's not me who is caring for the cat, its my boss coming up with cool requirements :)
|

July 3rd, 2008, 03:49 PM
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Quote:
quote:Originally posted by nasirmunir
It's not me who is caring for the cat, its my boss coming up with cool requirements :)
|
Isn't it nice to work for a boss who doesn't understand technology? *SIGH*
I thought of a moderately complex way to do all of this, if you care.
As each field receives focus, it sets a global JavaScript variable that points to itself. Then if the <BODY> receives focus (that is, if the user clicks outside of *any* <FORM> element) it moves the focus *back* to that last form field that had it.
Not ideal. But only way I can see to solve the <TEXTAREA> problem we both noticed.
|
|
 |