0

I've searched on internet but I just can't seem to figure this out. I got this Jquery function which I want to call in my php/html page. I'm an absolute noob when it comes to Jquery.

!function( $ ){
  var Keyboard = function ( element, options ) {
    this.$element = $(element)
    this.options = options
    if (this.options.display) {
      this.$keyboard = $('<div class="keyboard"><input type="text" class="input-keyboard"></div>').appendTo('body') 
    } else {
      this.$keyboard = $('<div class="keyboard"></div>').appendTo('body') 
    }

    this.$biginput = this.$keyboard.find('.input-keyboard')
    this.wait_timer = null
    this.init()
    this.listen()
  }
}

How can I call this function in a div or button?

<body>
    <button id="testKeyboard">Test open keyboard</button>
</body>

<script>
    $(document).ready(function(){
       $("#testKeyboard").keyboard();
    });
</script>
0

2 Answers 2

1

Without knowing this plugin, i would say something like this:

$(document).ready(function(){
   $("div, button").keyboard();
});

with ID:

$(document).ready(function(){
   $("#button_id").keyboard();
});

your php/html file, needs also the jQuery Library in the head part... For example:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="yourKeybordPlugin.js"></script>

maybe an other version. It should be before the plugin script...

<head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script src="yourKeybordPlugin.js"></script>
</head>
<body>
    <button id="testKeyboard">Test open keyboard</button>
    <script>
        $(document).ready(function(){
            $("#testKeyboard").keyboard();
        });
    </script>
</body>
Sign up to request clarification or add additional context in comments.

7 Comments

Hm, this doesn't seem to work, I will update my fiddle
First is for every button, every DIV, second is for sepcific ID.. you could also go with: $("#id_1, #id_2")
Hm, I have specified the files on top of my index file, but still it doesnt show anything, maybe I should try another version of jquery, i have jquery-1.11.0 in my library
the <script> should be in body tag
|
0

Call like this from your php file,

<script type = "text/javascript">
    $(window).keyboard();
</script>

Check now on JSfiddle, included Jquery plugin and added that in head section from the option. You can see the console.log firing.

http://jsfiddle.net/7ttq2gf0/2/

2 Comments

This works perfect in the fiddle, but in my actual page it doesn't work. Does it matter that the jquery file is an external resource? Do I need to call the class first for example, like in php and C#? I do have <script src="/js/jquery.keyboard.js"></script> on top of my index file
If you have not included the Jquery plugin in your file then you can add it as <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> or else you can download it and load it from your local server. This is enough to call the keyboard function.

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.