This is a discussion on "[SOLVED] Changing onfocus of a textbox" within the JavaScript Forum section. This forum, and the thread "[SOLVED] Changing onfocus of a textbox are both part of the Program Your Website category.
|
|
|
|
|
![]() |
||
[SOLVED] Changing onfocus of a textbox
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
[SOLVED] Changing onfocus of a textbox
I'm trying to learn javascript at the moment, but I can't figure out why the below code doesn't work. The page has a textbox you can't type in by using onfocus="blur()", then click the button to make onfocus="focus()" so you can type in it, then click again to change it back to onfocus="blur()". But it doesn't work. Can anyone tell me what I've done wrong?
Thanks
|
|
|
|
|||
|
Re: Changing onfocus of a textbox
OK, this should be accomplished by disabling the text box. Here is the entire code:
Cheers
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Last edited by Stuart; Jan 5th, 2008 at 03:06. |
|
|||
|
Re: Changing onfocus of a textbox
Thanks for your help, that works well.
I also got it to work in the original way I was trying, although I think I need to learn quite a bit more before I understand it. |
|
|||
|
Re: [SOLVED] Changing onfocus of a textbox
How did you solve it with the original? Then, I can explain it to you.
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
|
|||
|
Re: [SOLVED] Changing onfocus of a textbox
Thanks, here's the javascript.
What I don't understand about it is: 1. Why didn't the original function (setting window.document.form1.textbox1.onfocus=focus()) work? 2. Why does it only work if the function myfocus is declared while setting onfocus? If I change the myfocus function to a seperate function and then just call window.document.form1.textbox1.onfocus = myfocus() it doesn't work. 3. In the myfocus function it must refer to the element you want focused, I don't understand why? (I couldn't get it to work using self.focus() either). If you're able to explain any of things to me that would be great! Thanks |
|
|||
|
Re: [SOLVED] Changing onfocus of a textbox
OK. First of all, about the IE thing, your code is a bit strange and IE is picky with stuff like that.
Now to explain: 1. focus() is a function that puts the cursor into the textbox automatically. It doesn't disable the textbox like you wanted. 2. It's not usually a good idea to call functions in that particular area. It might be throwing errors. 3. In javascript, you always need to specify the exact element so that it works correctly. So, I suggest using my idea, since you run into less problems, and the code is cleaner. Cheers
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
|
![]() |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [SOLVED] Change Input Textbox Background Color | tejaxx | JavaScript Forum | 4 | Nov 19th, 2007 20:16 |
| [SOLVED] Changing Colours | crackafaza | PHP Forum | 37 | Oct 25th, 2007 11:55 |
| [SOLVED] Changing from html to CSS | mcdanielnc89 | Web Page Design | 16 | Oct 11th, 2007 04:29 |
| [SOLVED] Changing pictures on same page | R8515198 | JavaScript Forum | 7 | Oct 3rd, 2007 00:14 |
| events in NS (onfocus, onblur) | spinal007 | Web Page Design | 6 | Apr 27th, 2004 16:32 |