0

i am trying to add keyup function in wordpress so email address is directly populated from blog admin and when users type/edit the email address the corresponding link gets updated accordingly.

Here is my code

<input name="pluginemail" type="text" id="pluginemail" value="'.get_bloginfo('admin_email').' " onchange="kpoejy.updateSignupEmail();"> <a type="button" id="request_key" class="button button-primary" title="Request a new API key" href="http://somesitess.com/g11.php?pluginemail='.get_bloginfo('admin_email').'" onmouseenter="kpoejy.updateSignupEmail();" target="_blank">Request Key</a>

here is javascript in external file named javascr.js

 var kpoejy= function() {
   function updateSignupEmail() {
        jQuery('#request_key').attr('href', jQuery('#request_key').attr('href').split('?')[0] + '?pluginemail=' + jQuery('#pluginemail').val());
    }}

this is included using

    wp_register_script( 'javas-js', plugins_url( '/js/dist/javascr.misc.js', __FILE__ ), array( 'jquery' ) );

i tried wp_localize_script, wp_enqueue_script also but getting always same error

Uncaught ReferenceError: kpoejy is not defined

any idea where i am doing mistake. its for wordpress 4.8

2
  • 1
    Please provide the complete error message. Usually, the error message will tell you the file the variable was used. You can use that info as a clue to looking for the issue. Commented Jul 18, 2017 at 20:44
  • As Rick Hellewell already said, please update the question with more infos. Especially: How and where are you enqueuing? Can you see that the file is successfully loaded via network tab in the developer console?
    – kero
    Commented Jul 19, 2017 at 14:57

1 Answer 1

0

You're not properly defining the JS object. The following will work

var kpoejy = {
        updateSignupEmail: function() {
            // code
        }
    };

Because now you're making kpoejy an object (via {}) and inside assign the key updateSignupEmail a function.

What you did previously was to assign kpoejy a function, and inside that define another function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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