Closed (fixed)
Project:
Finder
Version:
7.x-2.0-alpha8
Component:
User interface
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
26 Apr 2012 at 15:13 UTC
Updated:
9 Nov 2012 at 17:35 UTC
I'd like to add a simple onFocus event to the Finder search field like so:
<input id="edit-test" name="test" value="" size="60" maxlength="128" class="form-text" type="text" value="Search here" onblur="if(this.value == '') { this.value='Search here'}" onfocus="if (this.value == 'Search here') {this.value=''}">
Can I add it through /sites/all/modules/finder/includes/form.inc or is it controlled through Drupal core?
Comments
Comment #1
damianrobinson commentedSomething like this should work for you:
I would suggest attaching this to the page as an external .js file, or you could even embed it as inline javascript.
Comment #2
danielb commentedI would attach the .js file through your site-specific template or a site-specific module.
Don't edit any Drupal code files, or files from within contrib module directories. It will create hassles when upgrading.
Comment #3
danielb commentedBest way IMO with this is not to put a value (i.e. a
val()) into the input, but rather to show the label "over" (not above) the input rather than before/above it. They're called "label over" scripts.I found that code somewhere - try googling it to find where?
And then you trigger which form element you want it in like this (usually in yet another js file with all your little jquery snippets):
I guess then you'll need some css to nudge the label into the right spot
Then you have full creative control of what the text looks like - and the bonus is, it can be made to look different to what the user's typed text looks like, so they don't assume they've typed in "Search here" themselves.
Sorry if I didn't explain it well, my finger hurts
Comment #4
danielb commentedComment #5
tuzonghua commentedThanks for the help!
Comment #6
tuzonghua commentedComment #7
gynekolog commentedThank you, this work fine for me: