1

I am trying to create a popup in WordPress. My popup opened but cancel and send buttons are not working.

This is my script and code :

Script

<script type="text/javascript" charset="utf-8">
    $(function() {
        function launch() {
             $('#sign_up').lightbox_me({centered: true, onLoad: function() { $('#sign_up').find('input:first').focus()}});
        }

        $('#try-1').click(function(e) {
            $("#sign_up").lightbox_me({centered: true, preventScroll: true, onLoad: function() {
                $("#sign_up").find("input:first").focus();
            }});

            e.preventDefault();
        });

        $('table tr:nth-child(even)').addClass('stripe');
    });
</script> 

and this is my form

<a href="#" id="try-1" class="sprited"><div class="call"></div></a>
<div id="sign_up">
    <h3 id="see_id">Request a call Back</h3>
    <div id="sign_up_form">
        <form id="form1" name="form1" action="../mail.php" method="post" >
            <label><strong>Name :</strong> <input class="sprited"/></label>
            <label><strong>Mobile No :</strong> <input class="sprited"/></label>
            <div id="actions">
                <input type="button" name="cancel" value="Cancel" class="close form_button sprited" />
                <input type="button" name="send" value="Send" class="form_button sprited" />
            </div>
        </form>
    </div>
    <a id="close_x" class="close sprited" href="#">close</a>
</div>
3
  • Wordpress doesn't really support inline javascript. If you view the source of the page you'll see that it get's sanitized by wordpress. Just put the javascript into a .js file somewhere and include it. Commented Apr 8, 2014 at 6:03
  • I have already created request.js file an include it in to header.php file. but it is not working Commented Apr 8, 2014 at 6:08
  • can you provide a link to the page in question? Commented Apr 8, 2014 at 6:12

1 Answer 1

2

Don't use inline javascript. As suggested by rosscower, add your javascript in a js file. You now need to enqueue it properly. Don't just dump it in the header. You will also need to think about conditional statements here to load your jquery file, if you only need to load it on a certain page you need to load it conditionally, otherwise this will load on all pages.

Example, you called your js file myjs.jsand you add it in a folder called js and want to load it only on the homepage, you'll do something like this

function register_my_js() {
if(is_home()) {
 wp_enqueue_script( 'my-script',   get_template_directory_uri() . '/js/myjs.js',    array(), '', true );
 }
}

 add_action( 'wp_enqueue_scripts', 'register_my_js' );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.