Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this jquery code inside my wordpress admin page that checks if the input value is empty.

$j(function(){
$j('form').submit(function(){

     var link = $j('#input').val();
    if(link == ''){
         alert('hi there');
    }

});

});

Now if the form is empty it will alert ' hi there'.

the plugin works fine but the alert does not show on the main page. Only in the admin section.

what would be the problem?

here is how I am calling jquery.

function test(){
wp_enqueue_script('jquery');
wp_enqueue_script('myscript', plugin_dir_url(__FILE__). 'js/test.js');


}
add_action('wp_enqueue_scripts','test');
add_action('admin_head','test');

I would like that if the value of input is empty, the alert show also in the wordpress homepage and not only in the admin page.

share|improve this question
    
The first bit of javascript is where exactly? In your test.js file? –  Wyck Jun 21 '12 at 16:05
    
yes Wyck thats test.js –  Ronny Jun 21 '12 at 16:33
add comment

2 Answers

function test(){
    wp_enqueue_script('myscript', plugin_dir_url(__FILE__). 'js/test.js',array('jquery'));
}
add_action('admin_print_scripts','test');
add_action('wp_head','test');
share|improve this answer
    
added that, but same thing Gembel. the alert only shows at the admin page. –  Ronny Jun 21 '12 at 16:39
    
hmm.. not sure why. is your js appear when you view page source? just in case you forget to add wp_head(); in your template :D –  Gembel Intelek Jun 21 '12 at 16:48
    
yes it does appear Gembel. –  Ronny Jun 21 '12 at 16:57
    
how about testing your js in jsbin? here is my test jsbin.com/omumit/edit#javascript,html –  Gembel Intelek Jun 21 '12 at 17:54
add comment

I believe the problem is that you are enquequeing jquery.

You don't need to do that, as WordPress does it by default. Just remove

wp_enqueue_script('jquery');

and everything should be fine.

share|improve this answer
    
that will never work. this is a plugin and I am calling jquery. –  Ronny Jun 21 '12 at 16:32
    
But you do not need to call jQuery! Trust me, I have recently submited plugin to WordPress.org and before approving it, I needed to remove jQuery call. There is no need for calling jQuery with plugins! –  OriginalEXE Jun 21 '12 at 16:35
    
ok well... gave that a shot too.. no changes. –  Ronny Jun 21 '12 at 16:40
    
What does your browser console say? –  OriginalEXE Jun 21 '12 at 16:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.