bgbs Posted January 20, 2012 Share Posted January 20, 2012 Hi I have this input box wrapped in php code 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 onfocus="if (this.value == 'Search...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search...';} So, the newb that I am, I tried this and got a syntax error <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"/>'; Any ideas how to properly integrate this javascript code into PHP? Thanks in advance Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted January 20, 2012 Share Posted January 20, 2012 I would actually assign both tasks to their own js functions, and call them via the event caller in your markup. however, to answer your question. <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(<?php echo $var['default']; ?>)" name="esc_attr(<?php echo $opt; ?>)" id="esc_attr(<?php echo $opt; ?>)" class="mc_input"/>'; Quote Link to comment Share on other sites More sharing options...
bgbs Posted January 20, 2012 Author Share Posted January 20, 2012 This way will not work because I'm already working within php. Another words the statement below is already contained in php brackets, so echoing php within php will not work. <?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; ?> Quote Link to comment Share on other sites More sharing options...
solanki_mahendra131 Posted January 31, 2012 Share Posted January 31, 2012 Hello, It is possible what you want to do, Just check code i have modified for you as follows: $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(<?php echo $var['default']; ?>)" name="esc_attr(<?php echo $opt; ?>)" id="esc_attr(<?php echo $opt; ?>)" class="mc_input"/>'; I have escape single quote in your string assignment as you have put whole string in '' code. Hope you can understand what i mean Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.