trouble with OnClcik event

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
herman101
Forum Newbie
Posts: 5
Joined: Tue May 18, 2010 10:15 am

trouble with OnClcik event

Post 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.
Last edited by Benjamin on Sat Jun 26, 2010 5:07 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: trouble with OnClcik event

Post 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.
Post Reply