tags:

views:

60

answers:

1

Hi there ,

I am not able to call a functions on onfocus and onblur events, both perfectly working in html but not in php here is code in php:

echo "<input value='Enter Name' onfocus= 'areaOnFocus(text1, 'Enter Name')' onblur='areaOnBlur(text1, 'Enter Name')' type='text' name='text1' id='text1'>";

both functions are called in script tag. I am sure that call to function is not made in this case as I am alerting in script tag , but nothing happen.

thank you in advance.

+1  A: 

Well you're messing up with quotes there. I think you're using single quotes everywhere to avoid problems with the double quotes enclosing the string, but then you have this problem:

onfocus= 'areaOnFocus(text1, 'Enter Name')'

the single quote starts the string at areaOnFocus and ends it before Enter name.

You can either play with double quotes spamming like this:

echo "<input value=\"Enter Name\" onfocus=\"areaOnFocus(text1, 'Enter Name')\" onblur=\"areaOnBlur(text1, 'Enter Name')\" type=\"text\" name=\"text1\" id=\"text1\">";

or - better - put the HTML code outside PHP blocks.

kemp
Did that, but no luck, strange is that when i run this much code only in separate sample.php file it works.
Rishi2686
You also said that to put html code outside php block, but how can i place it where it suppose to be
Rishi2686
just to check put it in html code, but still no success.
Rishi2686
Are you sure the final HTML generated is correct? Is the `areaOnFocus` function defined? Can you check on a javascript console for errors?
kemp
ok this is the whole code: code for js: function areaOnFocus(element, inputText) { //alert(inputText); //alert (element); if(element.value == inputText) { element.value=''; } } function areaOnBlur(element, inputText) { //alert(inputText); //alert (element); if(element.value=='') { element.value = inputText; } } and this one for in php:
Rishi2686
contd: echo "<input value=\"Enter Name\" onfocus=\"areaOnFocus(text1, 'Enter Name')\" onblur=\"areaOnBlur(text1, 'Enter Name')\" type=\"text\" name=\"text1\" id=\"text1\">";
Rishi2686