The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> getting html element name, javascript function
kryles
post Jan 18 2008, 01:41 PM
Post #1


Novice
**

Group: Members
Posts: 21
Joined: 30-November 07
Member No.: 4,437



Hi,

I just want to test which textbox the user is filling in. I think I'll use an onkeyup function call from the textbox, but how do I check the name of the textbox with focus?

I was thinking something along these lines but it doesn't seem to work (no message)

CODE


/* JS */

function focusField(curEl)
{
var current_ele = curEl;
alert("here");
if(current_ele.Name() == "Fname")
alert("yay!");
}

<!-- html -->
<input type="text" name="Fname" id="Fname" value="" onkeyup="focusField(this);"> <!-- pass element makign call -->


User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies(1 - 3)
Christian J
post Jan 18 2008, 07:57 PM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



You could do it like this:

CODE
if(curEl.name == "Fname")


(note that it's "name", not "Name").
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
kryles
post Jan 19 2008, 05:36 AM
Post #3


Novice
**

Group: Members
Posts: 21
Joined: 30-November 07
Member No.: 4,437



D'oh, should have thought of that since I've used

.innerHTML and .focus()

all lower case first words.

I'll give it a try Monday

thanks,= smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
kryles
post Jan 21 2008, 01:15 PM
Post #4


Novice
**

Group: Members
Posts: 21
Joined: 30-November 07
Member No.: 4,437



CODE
function focusPhone(curEl)
{
    var current_ele = curEl;

    if(current_ele.name == "phone1")
    {
              alert("yes, it worked!");
       }
}


worked great, thanks smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 28th March 2024 - 02:58 AM