[Skip to main content](#vessel-content)

#   Make custom field default text disappear onfocus

##

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago [\#103983](#103983) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#103983 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")* was created by *[goloon](/forum/user/12468-goloon "View goloon's Profile")*

I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this code or what I should insert to make it work.

The idea is that I want to add a description of the field for the user. The text title/label is not enough as a description field.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago [\#103985](#103985) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#103985 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Is there another way to create a description for the custom field item? If I use the default text it submits that value, which I dont want.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

13 years 6 months ago -  13 years 6 months ago [\#104072](#104072) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104072 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Hi,

You have to edit the file "administrator/components/com_hikashop/classes/fields.php" function "display()" in the class "hikashopTextarea", and in the .js add the desired code to remove the content on focus.

Last edit: 13 years 6 months ago by [Xavier](/forum/user/4105-xavier "View Xavier's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago -  13 years 6 months ago [\#104190](#104190) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104190 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

I'm assuming you mean line 1574 which is this line:
Code:

$js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value==\'\') this.value=\''.$value.'\';"';

can you give me the string to achieve the following:

onfocus delete default value
and
onsubmit if value is the default value don't submit value

Last edit: 13 years 6 months ago by [goloon](/forum/user/12468-goloon "View goloon's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

13 years 6 months ago [\#104213](#104213) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104213 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Hi,

Why not using the HTML5 "placeholder" tag ?
Compatible with new browser and it does not touch to the input value (so no problem with the submission of the form).
Otherwise, the javascript will be very complex.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago -  13 years 6 months ago [\#104230](#104230) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104230 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

ok. how do i do that???

Also, if it's not compatible with older browsers it might be a problem because it is the only description of the field. So if it is not compatible then there will be no description of the field.

Last edit: 13 years 6 months ago by [goloon](/forum/user/12468-goloon "View goloon's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

13 years 6 months ago [\#104308](#104308) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104308 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Hi,

You can simply use the content of $js but put this line out the if condition like: Code:

if($inside &amp;&amp; strlen($value) &lt; 1){ $value = addslashes($this-&gt;trans($field-&gt;field_realname)); $this-&gt;excludeValue[$field-&gt;field_namekey] = $value; $js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value==\'\') this.value=\''.$value.'\';"'; } $js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value==\'\') this.value=\''.$value.'\';"';

So everytimes, the default value will be removed onfocus.
And is the textarea is empty, it will reset the default value. You can add css properties in the javascript to change the color for example to show that the text is the description.

ps: for the previous method, you have to set a default value in the custom field configuration.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago -  13 years 6 months ago [\#104361](#104361) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104361 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Ok. This seems to work.

Problem 1: When I add to cart it submits the default value. I don't want default value submitted.

Problem 2: Why is it when I have a custom field enabled and I click "add to cart", it takes me to the checkout page? As opposed to, when I don't have a custom field, it simply adds to the cart and stays on the same page? I'd like to have the custom field enabled and stay on the same page once "add to cart" is clicked.

Last edit: 13 years 6 months ago by [goloon](/forum/user/12468-goloon "View goloon's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Xavier](/forum/user/4105-xavier "View Xavier's Profile")**
- [![Xavier's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar4105.png)](/forum/user/4105-xavier "View Xavier's Profile")
- [ Offline](/forum/user/4105-xavier)

Less More

- Posts: 13201
- Thank you received: 2322
-
-
-
- [](http://www.kidiweb.fr)
-

13 years 6 months ago [\#104766](#104766) by [Xavier](/forum/user/4105-xavier "View Xavier's Profile")  Replied by *[Xavier](/forum/user/4105-xavier "View Xavier's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104766 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Hi,

Problem 1: As you said before, you have to add a onsubmit in the form, check the custom field value and if it's equal to the default value, erase it.

Problem 2: The custom fields should not change the way the form is submitted, and the redirection. Have you edited any view related on the custom fields - product - cart ?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago [\#104880](#104880) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104880 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Problem 1: I don't know JS (that's why I asked how to do it), can you show me how? I assume this would go in the same script mentioned above.

I tried this but didn't work:
Code:

$js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value==\'\') this.value=\''.$value.'\';" onsubmit="if(this.value == \''.$value.'\') this.value = \'\';"';

Problem 2: No. All I know is that when the custom fields are enabled, once the add to cart button is clicked from the product page it goes to the checkout. If the custom field is not enabled it stays on same page.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

13 years 6 months ago [\#104907](#104907) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104907 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Hi,

I am really sorry to insist but, this is not the right solution.
As I said, using such trick will be very complicated for the javascript. Using the "placeholder" attribute will be easier and could be easily compatible with old browser.
By default, the placeholder attribute is compatible with:
* Firefox 4.0+
* Opera 11.01+
* Chrome 3.0+
* Safari 3.0+
* Internet Explorer 10+
For old version, there are some script, like a little jQuery script: Code:

$('[placeholder]').focus(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); input.removeClass('placeholder'); } }).blur(function() { var input = $(this); if (input.val() == '' &#124;&#124; input.val() == input.attr('placeholder')) { input.addClass('placeholder'); input.val(input.attr('placeholder')); } }).blur().parents('form').submit(function() { $(this).find('[placeholder]').each(function() { var input = $(this); if (input.val() == input.attr('placeholder')) { input.val(''); } }) });

And a little CSS Code:

.placeholder { color:#999; }

The script support all cases (focus, blur and form submission). So there is no more development to do.

About the attribute, you can set the placeholder attribute like other attributes (like the class or the javascript events).
So, something like: Code:

$js = 'placeholder="'.$value.'"';

should work good.

Best regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[goloon](/forum/user/12468-goloon "View goloon's Profile")**
- [![goloon's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/12468-goloon "View goloon's Profile") Topic Author
- [ Offline](/forum/user/12468-goloon)

Less More

- Posts: 84
- Thank you received: 1
-
-

13 years 6 months ago [\#104908](#104908) by [goloon](/forum/user/12468-goloon "View goloon's Profile")  Replied by *[goloon](/forum/user/12468-goloon "View goloon's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104908 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Jerome, can you tell me exactly what to do, as I am a little confused. I will have several custom fields, so will this apply to all of them? and will I still be able to set the default value through custom field backend admin?

Can you give me a step by step and where I should put the codes you mentioned?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14325
-
-

13 years 6 months ago [\#104956](#104956) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Make custom field default text disappear onfocus](/forum/4-how-to/81882-make-custom-field-default-text-disappear-onfocus#104956 "I have custom fields that are textareas and text inputs. Would like default value to disappear when the user clicks on the field. I know I can do this by using onfocus? Not sure where to look for this...")*

Jerome simply said to replace the line:
$js = 'onfocus="if(this.value == \''.$value.'\') this.value = \'\';" onblur="if(this.value=![=&#92;](/irritated.gif "=&#92;")'\') this.value=\''.$value.'\';"';

by:
$js = 'placeholder="'.$value.'"';

in the field.php file.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzQtaG93LXRvLzgxODgyLW1ha2UtY3VzdG9tLWZpZWxkLWRlZmF1bHQtdGV4dC1kaXNhcHBlYXItb25mb2N1cz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.106 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
