Jump to content

onclick on to input area?


astralaaron

Recommended Posts

What do you mean, when what condition is met? You use document.onclick if you want to capture any click event. If you want to catch a click event on a specific element then you just use the onclick handler for that element instead of document.

Link to comment
Share on other sites

function focus(){var field = document.getElementById("comment");field.style.border = '1px solid #ffffff';}<textarea onclick='focus();' class="input_1" id="comment" name="comment" rows="4" cols="68"></textarea>is this correct? cant get anything to happen here

Link to comment
Share on other sites

Yeah, that should work. You can generalize it.function focus_el(el){ el.style.backgroundColor = 'red'; el.style.border = '1px solid #ffffff';}<textarea onclick="focus_el(this);" class="input_1" id="comment" name="comment" rows="4" cols="68"></textarea>

Link to comment
Share on other sites

Rules? We don't need no stinkin' rules!Seriously, if the code works and it's not grossly inefficient or uses a deprecated property that might disappear tomorrow, you're probably okay. As to the question, heck yes, make your form elements look the way you want. I for one prefer a 1px border all one color around my text inputs and text areas.If it doesn't work, debug debug debug.One exception: input type="file" resists style changes like the plague. It's a blot on the entire enterprise.

Link to comment
Share on other sites

By the way, just copying JSG's code won't work - the JavaScript doesn't have script tags around it.

Link to comment
Share on other sites

There's also nothing there to make the color change back, all it does is change to red when you focus it. It doesn't do anything when it loses focus. You can use an onblur event to do something when it loses focus.

Link to comment
Share on other sites

There's also nothing there to make the color change back, all it does is change to red when you focus it. It doesn't do anything when it loses focus. You can use an onblur event to do something when it loses focus.
thanks everyone, and especially for the onblur :) i was just trying to figure out how to tell when you click away from the element.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...