SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    What this onClick() do?

    Hi guys,

    I have codes below,
    Code:
        <div id="uploadBox" class="well" onClick="$('#photoimg').click();">
            <button class="btn btn-mini btn-primary" type="button">Upload File</button>
        </div>
        <input type="file" class="hide" name="photoimg" id="photoimg" onchange="$(this.form).submit();"/>
    Just wondering what these codes mean,
    Code:
         onClick="$('#photoimg').click();"
    Okay let me guess, when I click the button, it will invoke the <input type="file" ...> and auto submit the form with the codes,
    Code:
    onchange="$(this.form).submit();
    Am I right or am I wrong?

    Thanks in advanced.
    Quality codes are optimized and tested...
    Click here for inspiration..

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Hi there,

    You are right.

    Code JavaScript:
    $('#photoimg').click();

    is shorthand for:

    Code JavaScript:
    $('#photoimg').trigger('click');

    which will execute all handlers and behaviours attached to the matched element.
    http://api.jquery.com/trigger/

    I'm not sure why you would want to do this, though.
    First off, in-line event handlers are usually a bad thing, as they impact negatively on the readability and maintenance of your mark-up.
    Secondly, wouldn't it be less confusing to have a "Select File" button and a "Submit" button?

    Hope that helps.

  3. #3
    Patience... bronze trophy solidcodes's Avatar
    Join Date
    Jul 2006
    Location
    Philippines
    Posts
    936
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Actually it's just a tutorial from here,
    http://www.danmorgan.net/programming...bootstrap-php/

    I'm just trying to understand.
    Quality codes are optimized and tested...
    Click here for inspiration..

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,941
    Mentioned
    215 Post(s)
    Tagged
    12 Thread(s)
    Ah, ok. With a bit more context it makes more sense.
    I still stand by what I said about in-line event handlers, though.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •