Is it possible to set a form element's title with Javascript and DOM?

C

Christopher Nelson

I want to vary the title of a form element (the text that pops up in a
tooltip-like window when the mouse hovers over the element) as a user
interacts with the form but I can't find a title property for elements
or anything like that in the DOM. I hope I'm missing something or
there's some clever technique for faking this. Any suggestions?

Chris
 
M

McKirahan

Christopher Nelson said:
I want to vary the title of a form element (the text that pops up in a
tooltip-like window when the mouse hovers over the element) as a user
interacts with the form but I can't find a title property for elements
or anything like that in the DOM. I hope I'm missing something or
there's some clever technique for faking this. Any suggestions?

Chris


You don't say what will cause it to vary.

Here's a page that varies the title to reflect the contents of the textbox.

<html>
<head>
<title>titled.htm</title>
<script type="text/javascript">
function titled(that) {
document.getElementById("what").title = that.value;
}
</script>
</head>
<body>
<form>
<input type="text" name="what" id="what" onkeyup="titled(this)" title="">
</form>
</body>
</html>
 
A

arun

hi Chris,
try this works
arun
------------------------
<html>
<head>
</head>
<body>
<form name="frm" title="title" alt="title">
<input type="text" name="el" width="100" value="">
<input type="text" name="el1" width="100" value="">
<input type="button" value=" Alter "
onclick="this.form.alt='tooltip';this.form.title='tooltip'">
<input type="button" value=" Restore "
onclick="this.form.alt='title';this.form.title='title'">
</form>
</body>
</html>
 
C

Christopher Nelson

McKirahan said:
You don't say what will cause it to vary.

I want to do it in the onchange of a select. That much I can manage.
Here's a page that varies the title to reflect the contents of the
textbox.
...
document.getElementById("what").title = that.value;
...

Thanks. I didn't find a title property at
http://www.w3schools.com/js/js_obj_htmldom.asp and Google didn't find a
better reference for me. I probably should have just _tried_ it but
then I'd have fairly low confidence about its browser dependence. Is
it standard? Where can I find documentation?
 
M

Michael Winter

Christopher Nelson wrote:

[snip]
Is [title] standard?

Yes. The title property is defined in the HTMLElement interface of the
HTML module.
Where can I find documentation?

The W3C DOM documentation (<URL:http://www.w3.org/DOM/> and
<URL:http://www.w3.org/DOM/DOMTR>) is the definitive reference.
Currently DOM Levels 1 and 2 are implemented in modern user agents to
various degrees.

The DOM is defined in terms of interfaces, with some interfaces
inheriting from others. For example, HTMLElement inherits from the
Element interface, which in turn inherits from Node. Every HTML
element will implement the properties and methods of those three
interfaces, plus those of any specialised interfaces (such as
HTMLSelectElement).

Hope that helps,
Mike
 
R

RobG

Christopher Nelson wrote:
[...]
Thanks. I didn't find a title property at
http://www.w3schools.com/js/js_obj_htmldom.asp and Google didn't find a
better reference for me. I probably should have just _tried_ it but
then I'd have fairly low confidence about its browser dependence. Is
it standard? Where can I find documentation?

w3schools is a useful though cursory primer. Mike has given
links to the DOM specs, here is a link to the HTML spec. Note
that at the bottom of the page are links to the 'Index of
Attributes' and 'Index of Elements'. These provide useful
cross-references.

<URL:http://www.w3.org/TR/html4/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top