Page 1 of 1

PHP input form javascript integration failed

Posted: Fri Jan 20, 2012 1:20 pm
by bgbs
I have this input box wrapped in php code. (I've only pasted the portion of that php code.)

Code: Select all

<?php
case 'email':
            $html .= '
    <input  name="s" id="s" value="Email..." type="text" size="18" value="'.esc_html($var['default']).'" name="'.esc_attr($opt).'" id="'.esc_attr($opt).'" class="mc_input"/>';
    break;
?>
And I would like to add this javascript into the input form

Code: Select all

onfocus="if (this.value == 'Search...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search...';}
I tried this and got a syntax error

Code: Select all

<input  name="s" id="s"  onfocus="'.if (this.value == 'Search...') {this.value = '';}.'" onblur="'.if (this.value == '') {this.value = 'Search...';}.'" value="Email..." type="text" size="18" value="'.esc_html($var['default']).'" name="'.esc_attr($opt).'" id="'.esc_attr($opt).'" class="mc_input"/>';
Someone suggested to me that I should be using $html plus slashes to accomplish this, but I dont think thats right, because the onfocus and onblur should be inside the input tags.

Any help appreciated
Thanks in advance

Re: PHP input form javascript integration failed

Posted: Fri Jan 20, 2012 1:35 pm
by Celauran
The problem is that you've got a number of mismatched quotes.

Code: Select all

$html = '<input  name="s" id="s"  onfocus="if (this.value == \'Search...\') {this.value = \'\';}" onblur="if (this.value == \'\') {this.value = \'Search...\';}" value="Email..." type="text" size="18" value="'.esc_html($var['default']).'" name="'.esc_attr($opt).'" id="'.esc_attr($opt).'" class="mc_input"/>';