X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Pre filled search text box (https://forum.x-cart.com/showthread.php?t=38048)

Warwick 03-05-2008 03:32 AM

Pre filled search text box
 
Is there somebody how knows how to pre fill the search text box with something lik 'Start searching ...'

And the so that when a visitor clicks in this text i.e. the search text box, it'll dissapear i.e. becomes empty?

At this moment I have {$searchstring|escape:'html'} in it because I use the Smart Search mod.

Any help is appreciated.

balinor 03-05-2008 03:57 AM

Re: Pre filled search text box
 
Add this to the search input box:

value="search for products..."onFocus="this.value=''"

Warwick 03-05-2008 03:59 AM

Re: Pre filled search text box
 
thanks balinor but should I then replace the '{$searchstring|escape:'html'}' whta is in it now?

balinor 03-05-2008 04:05 AM

Re: Pre filled search text box
 
If that is set for the value, yes, you can remove that.

Warwick 03-05-2008 04:34 AM

Re: Pre filled search text box
 
That works, love ya ;)

You have any idea if this'll work with language variables?

I tried replacing value="search for products..."onFocus="this.value=''"

with $lng.lbl_my_text but that doesn't work :(

balinor 03-05-2008 04:41 AM

Re: Pre filled search text box
 
Use:

value="{$lng.lbl_my_text}" onFocus="this.value=''"

kube 03-05-2008 05:03 AM

Re: Pre filled search text box
 
You could put the original value back too if the field was left empty... (similar to apple.com's prettysearch)...

value="{$lng.lbl_my_text}" onFocus="this.value='';" onBlur="if(this.value=='') this.value='{$lng.lbl_my_text}';"

The code might be a little bit much, but you never know

Warwick 03-05-2008 10:15 PM

Re: Pre filled search text box
 
You guys are the best! Works like a charme :)

But kube, what do you mean with the pretty search example, I noticed Apple's search box, but when you leave it empty, no search is performed. Can you explain what you're after with this code (which I've implemented like you said)?

kube 03-06-2008 03:04 AM

Re: Pre filled search text box
 
My bad. What happens with apple's search field is obviously a little sophisticated. But for usability, if the field remains empty and you click elsewhere on the page instead of searching, the field returns to a default value (ie. it will return to saying 'Search' if left empty).

onFocus means the item is active
(in this case it will remove value of box) onFocus="this.value='';"

onBlur means the item is not active
(will return a value back into box if it is left empty) onBlur="if(this.value=='') this.value='{$lng.lbl_my_text}';"

carpeperdiem 03-06-2008 04:33 AM

Re: Pre filled search text box
 
I agree with kube - apple.com search is very user friendly. A good model to emulate. The search box says, "search" until you click in it (then it is empty, waiting for input). As soon as the search results refresh, the search box again says, "search". As in kube's post #7

boomobile 03-06-2008 09:56 AM

Re: Pre filled search text box
 
Can you do this for "product options" selection box as well? Some of our customers don't realize that if they don't choose an option, then x-cart will use the first option. I want the box to read, "Please make a slection" and not be able to process until they do.

Does anyone know the code and where to place them?

kube 03-06-2008 10:15 AM

Re: Pre filled search text box
 
That may, I would have thought, require a little more involvement including a few templates to edit and digging through the relevant javascript file that it talks to.

1. You would need to create in .tpl a default OPTION, say "Please choose".
2. With the js if the OPTION still remains as "Please choose" prompt with an alert.

There's probably more to it than that. But i haven't got 4.0 code on me :(

bobb 03-06-2008 10:35 AM

Re: Pre filled search text box
 
No need for code. Make the first option ( # zero) a heading like CHOOSE XYZ.. Then don't allow it pass validation.
Code:

if (product_option('RATIO_+_UNIT').selectedIndex == 0)
{ alert('You must select a ratio and carrier!'); return false; }

else { return true; }

Well that is code, but it gets input as data!

carpeperdiem 03-06-2008 06:40 PM

Re: Pre filled search text box
 
Here's another way to do this:

http://forum.x-cart.com/showthread.php?p=189859#post189859

carlisleglass 03-10-2008 07:10 AM

Re: Pre filled search text box
 
Improved it a little bit - say you have enter a search term, click away from the box by accident and click back on it, it will clear the contents. This coding will check to see if anything apart from the default text is in the box, and if the default text is not in the box, will not clear it.

value="{$lng.lbl_my_text}" onFocus="if(this.value=='{$lng.lbl_my_text}') this.value='';" onBlur="if(this.value=='') this.value='{$lng.lbl_my_text}';" />

kube 03-10-2008 07:15 AM

Re: Pre filled search text box
 
Thanks carlisle works great,

I was going to post something not to dissimilar to that - but I was worried about filling your page with excess code.


All times are GMT -8. The time now is 03:06 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.