Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Anyone know how to access a label control (or whatever it is) through the control it is associated with?

 

Example:

 

<label for="email">Email Address</label>

<input type="text" id="email" size="20" maxlength="50" />

 

I want to change the font color of the label associated with the control when the user leaves the control.

Posted

<div id="div_email">Email Address</div>

<input type="text" id="email" size="20" maxlength="50" onblur="change_color(this);"/>

 

in JS, change the class of the div

 

change_color(formobject) {

var label_id = document.getElementById('div_' + formobject.id)

label_id.class = 'highlighted';

{

 

I forget the id attribute in JS, might be name? also, not sure about the css class attribute. Hope it helped.

Posted
Thanks for the effort, though, I was specifically looking for a relationship reference between a label tag and a textbox control. Notice the label control in my example did not have an id. Accessing an element by assuming it has a certain id (div*) is cheap. I'm thinking there has to be something in the dom that references the textbox from the label tag, otherwise there would be no point for the 'for' attribute.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...