Member
Member
makar   2010-08-09, 14:17
#1

Hello,

I am looking for a way to add informative text to a search box, i.e. a text that is shown there by default and disappears when cursor is put there.

I have located the following line in template-functions.php:

`

Administrator
Administrator
acrylian   2010-08-09, 15:44
#2

You should never modify core files. You may want to look at the searchform function (see documentation for the correct name), that has a parameter to change the button text.

Member
Member
makar   2010-08-09, 17:43
#3

It is text in input rather then the button, that I would like to see. Perhaps I did not explain it well, so for example you can observe it on this site:

http://blog.js-development.com

Where in the input field there is "Search..." text. I took a look at source of this site and it looks like I will need to modify the core, as I cannot see how to implement this with ZP's function printSearchForm.

Administrator
Administrator
acrylian   2010-08-09, 18:09
#4

Ok, I missunderstood. I suggest to try using jQuery to modify that. Then you would not need to hack the core.

If you really need to modify the function itself, copy it, rename it and use it as a theme custom function (see the theming tutorial about that) instead of hacking.

Member
Member
makar   2010-08-09, 18:55
#5

Looks like this jQuery plugin should do the trick:

http://plugins.jquery.com/project/default-text

From what I've gathered so far (I am quite new to JS and haven't dealt with jQuery), this example code should work just by including it in the body:

`

$('input').defaultText({ defText: 'Bob' });

`

And of course there is in the head:

`

Administrator
Administrator
fretzl   2010-08-09, 19:06
#6

Put this in the head of your page and see if this is what you want.
It's just a jQuery snippet found on the internet.

`

//

`

Member
Member
makar   2010-08-09, 19:17
#7

Oh yes, that is exactly what I wanted! Plus it's quick and simple.

Thank you very much for sharing the code!

Member
Member
jackdaw   2012-03-30, 06:59
#8

I added the above code of fretzl to my header. It works, but after the first search is done, I'd like to add the text 'Search more...' to the input field, so that visitors know they can specify their search even more. How can I do that?

Administrator
Administrator
acrylian   2012-03-30, 09:19
#9

That will most likely be on the search.php itself. You probably need to check for results or empty results to change the text accordingly (that is needed as you technically can access the search page without prior search - depends on your site naturally).

Member
Member
sbillard   2012-03-30, 16:25
#10

The simplest way to do this would be to change the text in the above script to be a PHP statement

Change both instances of 'Start search here' to ''

Of course this presumes that your them has setup the $searchwords variable. Not all themes do this.

Member
Member
jackdaw   2012-03-31, 12:57
#11

Thanks! It was even simpler than I thought. Just adjusting those lines in the search.php file was enough.

Junior Member
Junior Member
Tedsds   2012-04-05, 10:18
#12

How can I use the code to populate both the email address field and product search? I've tried it several ways and the text in only 1 field will disappear, while the other stays there.

Administrator
Administrator
acrylian   2012-04-05, 10:56
#13

What a really clever spam attempt...:-(

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.