astralaaron Posted March 28, 2008 Share Posted March 28, 2008 Hey, I have an understanding of the onclick / onmouseover events, I was wondering if there is a way to detect if a user clicked into any type of form input, (textarea, text field, inputs, radios etc... Link to comment Share on other sites More sharing options...
justsomeguy Posted March 28, 2008 Share Posted March 28, 2008 Yeah, you use onclick. Link to comment Share on other sites More sharing options...
astralaaron Posted March 28, 2008 Author Share Posted March 28, 2008 sorry I actually am having problem when they click anywhere outside of the textfield, document.onclick .. how do i make something happen when that condition is met Link to comment Share on other sites More sharing options...
justsomeguy Posted March 28, 2008 Share Posted March 28, 2008 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 More sharing options...
astralaaron Posted March 28, 2008 Author Share Posted March 28, 2008 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 More sharing options...
justsomeguy Posted March 28, 2008 Share Posted March 28, 2008 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 More sharing options...
astralaaron Posted March 28, 2008 Author Share Posted March 28, 2008 well is it against the rules to change the styles of the form elements? because I have that exact code and i'm getting no results Link to comment Share on other sites More sharing options...
Synook Posted March 28, 2008 Share Posted March 28, 2008 Its not against the rules. What does your code look like? Link to comment Share on other sites More sharing options...
astralaaron Posted March 28, 2008 Author Share Posted March 28, 2008 well I pasted justsomeguy's code into a new file and it worked, I just cant seem to get the document.onclick to make the style change back Link to comment Share on other sites More sharing options...
jeffman Posted March 28, 2008 Share Posted March 28, 2008 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 More sharing options...
Synook Posted March 29, 2008 Share Posted March 29, 2008 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 More sharing options...
justsomeguy Posted March 31, 2008 Share Posted March 31, 2008 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 More sharing options...
astralaaron Posted April 6, 2008 Author Share Posted April 6, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.