• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: On Click, Clear Default Field Value

On Click, Clear Default Field Value 14 years 5 months ago #12084

Is there a way to have a field's default value cleared when a user clicks in the field?

Figured it out. Use onclick="this.value='';"
Last Edit: 14 years 5 months ago by ChangeFive. Reason: Figured it out.
The administrator has disabled public write access.

Re:On Click, Clear Default Field Value 14 years 5 months ago #12107

  • andreic
  • andreic's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 745
  • Thank you received: 66
Hello,

You could also try adding the following attributes in the "Additional attributes" property of your field:
onfocus="if(this.value == 'your_default_value') this.value ='';" 
onblur="if(this.value == '') this.value='your_default_value'"
Please note: my help is not official customer support. To receive your support, submit a ticket by clicking here
Regards,
RSJoomla! Development Team
Last Edit: 14 years 5 months ago by andreic.
The administrator has disabled public write access.
The following user(s) said Thank You: johanndj

Re:On Click, Clear Default Field Value 13 years 11 months ago #13618

  • sniffles
  • sniffles's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 2
Hi

In a Textarea you can write your Text into the "Default Value".
To remove the text by klicking into the Textarea and to show it again when klicking outside the Textarea, use teh following code:
onfocus="if(this.value=='Name'){this.value=''}" onblur="if(this.value==''){this.value='Name'}"

while "Name" stays for the "Default Value" Entry.
Best regards
Sniffles
Last Edit: 13 years 11 months ago by sniffles.
The administrator has disabled public write access.
The following user(s) said Thank You: maxgdias

Re:On Click, Clear Default Field Value 11 years 1 month ago #26934

  • paypal14
  • paypal14's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 21
You also should mention that the value (whatever it is - in this example the word "Name") must be in the Default value or this doesn't work.
The administrator has disabled public write access.

Re:On Click, Clear Default Field Value 10 years 8 months ago #28480

  • al3xw1ll1ams
  • al3xw1ll1ams's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 1
Use this for best results:

placeholder="Your_Default_Text"

put that in the Additional Attributes part.
The administrator has disabled public write access.
The following user(s) said Thank You: renemori7

Re:On Click, Clear Default Field Value 10 years 5 months ago #29463

Simple and effective. Thank you!
al3xw1ll1ams wrote:
Use this for best results:

placeholder="Your_Default_Text"

put that in the Additional Attributes part.
The administrator has disabled public write access.

Re:On Click, Clear Default Field Value 10 years 4 months ago #29906

Hi, I've the problem that my site is multilanguage. So, as Additional Atributes field isn't multilanguage, your solution doesn't work for me.

There is any work around to solve this?
onfocus="if(this.value == 'your_default_value') this.value ='';" 
onblur="if(this.value == '') this.value='your_default_value'"

Regarding your code, is there any way of referencing 'your_default_value' in your code, with the value in the field Default Value which is multilanguage allowed??

for example ...
onfocus="if(this.value == 'the_one_declared_on_Default_Value_box') this.value ='';" 
onblur="if(this.value == '') this.value='the_one_declared_on_Default_Value_box'"

Thanks for your help

joan
Last Edit: 10 years 4 months ago by jc.sanjurjo.
The administrator has disabled public write access.

Re:On Click, Clear Default Field Value 10 years 4 months ago #29920

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
EDIT, a simpler solution.

Create a Freetext element at the bottom of your form (it is important to be at the bottom)
<script type="text/javascript">
 
var field = document.getElementById('field_id'); // get a reference to the input field
 
field.setAttribute('placeholder', field.value); // add the placeholder attribute the same as the value
field.value = ''; // clear the value so you can see only the placeholder
 
 
</script>
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 10 years 4 months ago by cosmin.cristea.
The administrator has disabled public write access.
The following user(s) said Thank You: johanndj

Re:On Click, Clear Default Field Value 10 years 3 months ago #29934

Hi cosmin.cristea, thanks for your answer but unfortunatelly I don't understand what you mean.

Did you mean that I should create a new free text element for each Form Field?

My problem is that my site is multilanguage, and in the solution proposed in this thread, in order to clear Default Field Value on click, its mandatory to set the "default.value" in the Additional Atributes part. But the additional attributes part it's not multilanguage. So, I can declare in Additional Atributes part the Default Field Value, just for one language. That's the problem

Please, any advice on how to solve will be appreciated

Joan
Last Edit: 10 years 3 months ago by jc.sanjurjo.
The administrator has disabled public write access.

Re:On Click, Clear Default Field Value 10 years 3 months ago #29937

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Please follow these steps:

Create a Free text field element at the bottom of your form (the last element should be a Free text) and insert this:
<script type="text/javascript">
 
var elements = document.getElementsByTagName('input');
	for (var i = 0; i < elements.length; i++) {
	var element = elements[i];
	var tagName = element.tagName || element.nodeName;
	var elType = element.type ? element.type : '';
		if (tagName == 'INPUT' && elType == 'text') {
			element.setAttribute('placeholder', element.value);
			element.value = '';
		}
}	
</script>

Next step is to add a default value (click edit and insert it in the Default Value) for all of your textbox fields. The script will search for them and add the placeholder attribute if it finds a value.

Try it and let me know!
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: edrad80
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!