Results 1 to 6 of 6
  1. otacon's Avatar
    CrackBerry Addict

    Posts
    811 Posts
    PIN
    28A006EA
    Thread AuthorThread Author   #1  

    Default HTML5: Button Onclick

    Dear developer gurus,

    Need some help here. Am starting to dabble in App Dev and chose HTML5 as it seems to be easier, and I have 'some' very basic knowledge in html language. Used to study C++ but kinda forgot most of it now

    I have actually completed writing the frame of the app, but am stuck at a certain point:

    I have a button, which is shown in code below:
    <p><center><button><img src="BeginTest.gif"/></button></center></p>

    If I want to display a picture upon clicking the button, how should the code be like? Do I need a separate javascript running in the body?

    Would appreciate some help. Can send you the code if you want to have a look.
    Curve 8300 -> Curve 8320 -> Bold 9780 -> Torch 9860 -> Bold 9900 -> Z10
    iPad 1 -> iPad 2 -> Playbook 64gb
    Visit http://bbappdeveloper.blogspot.com/
  2. recompile's Avatar
    CrackBerry Abuser

    Posts
    307 Posts
    #2  

    Default

    You could use the onClick attribute in the button tag or attach an event to the element like element.addEventListener('click',function,false)

    This explains it all: Advanced event registration models

    You may want to pickup a book on javascript and work through a few examples.
    Thanked by:
    otacon (06-25-2012) 
  3. otacon's Avatar
    CrackBerry Addict

    Posts
    811 Posts
    PIN
    28A006EA
    Thread AuthorThread Author   #3  

    Default

    Thanks. I'll check it out.
    Curve 8300 -> Curve 8320 -> Bold 9780 -> Torch 9860 -> Bold 9900 -> Z10
    iPad 1 -> iPad 2 -> Playbook 64gb
    Visit http://bbappdeveloper.blogspot.com/
  4. ignites's Avatar
    CrackBerry Genius

    Posts
    1,670 Posts
    #4  

    Default

    <p><center><button><img src="BeginTest.gif" onclick="dosomething()"/></button>
    </center>
    </p>

    <script>
    function dosomething(){
    //write some code to show an image.
    }</script>
    Developer for easyDial for BlackBerry Bold & inLink for BlackBerry PlayBook
    Find me online via twitter, or on the techfruits.com webpage & twitter account
  5. otacon's Avatar
    CrackBerry Addict

    Posts
    811 Posts
    PIN
    28A006EA
    Thread AuthorThread Author   #5  

    Default

    Yup. Got that earlier.

    onclick=window.onload(......)

    Thanks for helping...
    Curve 8300 -> Curve 8320 -> Bold 9780 -> Torch 9860 -> Bold 9900 -> Z10
    iPad 1 -> iPad 2 -> Playbook 64gb
    Visit http://bbappdeveloper.blogspot.com/
  6. Superfly_FR's Avatar

    Posts
    5,686 Posts
    PIN
    Hey, what did you expect ?
    #6  

    Default

    Quote Originally Posted by otacon View Post
    I have a button, which is shown in code below:
    <p><center><button><img src="BeginTest.gif"/></button></center></p>
    I strongly suggest you first get some HTML5/CSS updates. For example, the code for your button is "illegal" regarding current W3C guidelines ... Moreover, you may have to find workarounds (using JS) that are not anymore necessary to handle simple tasks that will throw you in compatibility issues.

    Quote Originally Posted by otacon View Post
    onclick=window.onload(......)
    nope ... ;-)

    Here's a working sample that may lead you to learnings. I've tried both to include basic JS variables manipulation: some are passed by the function call (theImage,imgHeight,imgWidth), one is hardcoded in the function (myImageUrlPath). Tried also to keep the HTML code simple but (almost) clean. Note that the use of CSS styling "inline" for the div/button may (should) have been done with a Style definition (<style></style>) inside the header (<head></head>) section ... but nobody's perfect ;-)

    [HTML]
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>My image poper page</title>
    <script type="text/javascript">
    // function to display an image, with three parameters (image to display, its height, its width)
    function showImage(theImage,imgHeight,imgWidth) {

    var myImageUrlPath = "http://actu-mobiles.fr/wp-content/uploads/2012/02/";
    // where are full size images stored
    window.open(myImageUrlPath + theImage, "imgPopup", "menubar=no, status=no, scrollbars=no, height="+imgHeight+", width="+imgWidth);
    // opens a popup with image inside, sized to the proper dimension

    }
    </script>
    </head>
    <body>
    <div id="myRootDiv" style="text-align:center; width:100%;">
    <form id="myForm">
    <input type="button" id="myButton" style="height:169px; width:98px; background-color:transparent; border:none; background-image:URL('http://cdn-store.crackberry.com/store_images/product_images/smartphones/blackberry_mini/1410_98x169.png')" onclick="showImage('blackberry_bold9900_450_3.jpg' ,'500','500')">
    </form>
    </div>
    </body>
    </html>
    [/HTML]Remember ... little steps after little steps :
    1/ HTML5
    2/ CSS3 (you'll be surprised, can handle a lot of things we previously made with JS)
    3/ Javascript

    Hope it helps.
    Last edited by Superfly_FR; 06-29-2012 at 04:54 AM.
    "I speak English like a Spanish Cow"
    I'm a StockBerrian, proudly holding 50 150 250 400 (I'm done !) BlackBerry shares
    I'm no sheep; never been white and will never be called black again.
    Thanked by:
    otacon (07-03-2012) 

Posting Permissions