Showing posts with label html. Show all posts
Showing posts with label html. Show all posts

Wednesday, July 6, 2011

When you can't onclick() in html

Change:

<button onclick="myFunction()">Click me</button>

To one of:
way 1 with .onclick with anonymous function
<body>
    <button id="myButton">Click me</button>
    <script>document.getElementById("myButton").onclick = function(){ stuff };</script>
</body>

way 2 with .onclick with named function
<body>
    <button id="myButton">Click me</button>
    <script>function myFunction() { stuff };
    document.getElementById("myButton").onclick = myFunction;</script>
</body>

way 3 with .addEventListener() with named function
<body>
    <button id="myButton">Click me</button>
    <script>document.getElementById("myButton").addEventListener('click', myFunction, false);</script>
</body>

Remember to put the addEventListener script after you have created the button. If you have to put it in the head, put the line of script inside a jQuery ready like
<!-- try not to do this though -->
<head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            document.getElementById("myButton").addEventListener('click', myFunction, false);
        }
</script>
</head> 

<body>
    <button id="checkButton">Click me</button>
</body>

But it's better practice to put js right before the closing of the body tag.



If your function has arguments...

Change:

<button onclick="myFunction('arg1')">Click me</button>

To
<body>
    <button id="myButton">Click me</button>
    <script>document.getElementById("myButton").addEventListener('click', function(){ myFunction('arg1') }, false);</script>
</body>

Saturday, March 26, 2011

making youtubelooper.com notes

http://youtubelooper.com/

htmlentities() - to prevent xss
urlencode() - to keep the lyric's spaces and new lines
<label> - to click on


<textarea onclick="this.focus(); this.select();"></textarea> - make it select all when clicked

style changes

Fixed something on bottom right of page with CSS:

     position: fixed;
     bottom: 0;  
     right: 0;

css to make pointer into a hand
    cursor: pointer;


get jquery: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
jQuery to focus on something at the beginning:

  $(document).ready(function(){
      $("#inputboxid").focus();
  });



name.com sigh doesn't allow very long URL's

Friday, March 25, 2011

checkboxes and labels should get married

Yes, they should. Why limit yourself to only clicking on the tiny checkboxes? It's not a game.
Please group the text of input checkboxes together with labels!



html:
<label><input name="option" value="1" type="checkbox">The text is so long so you can have lots of places to click</label>