Page 1 of 1

trouble with OnClcik event

Posted: Sat Jun 26, 2010 4:00 am
by herman101
Hi all,

for some reason I do not understand the $_SESSION variable I guess.

I have a form with a text box with some initial text. When a person wants to enter the text box the default text disappears. This works fine. But the text should only disappear once. So When onclick is done the text should be removed once. I thought doing this using the session variable:

Code: Select all

function clickevent(){
	
	if(!isset($_SESSION['click'])){
		echo "\"forms.recepttoevoegen.naam.value =''\"";
		$_SESSION['click']=true;
	}
	
}
In the script I all add. Session start(); But each time I enter the text box the text disappears. The $_SESSION['click'] is not set to true or it does not remember this. I have no clue. I miss something small.

Re: trouble with OnClcik event

Posted: Sat Jun 26, 2010 8:47 pm
by Jonah Bron
The session variable is for storing information concerning a user's session. For example, if you had a shopping cart, you would put what the user had in his cart into the session variable.

What you're doing requires Javascript. Here is an example of a textbox with the appropriate javascript.

Code: Select all

<input type="text" value="Enter text here!" onfocus="if (window.text_entered_var==undefined)) { this.value = ''; window.text_entered_var = true;}" />
This one will even re-fill the textbox with the placeholder text if left empty.

Code: Select all

<input type="text" value="Enter text here!" placeholder="Enter text here!" onfocus="if (this.value==this.getAttribute('placeholder')) this.value = '';" onblur="if (this.value.length<1) this.value=this.getAttribute('placeholder');" />
Make sure you populate the "placeholder" attribute with the same value as the "value" attribute.