onClick

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken

    #1

    onClick

    Does php work with onClick in an html input statement?

    <HTML>
    <input type="button" name="add_pictu re" value="Add another picture"
    onClick="<?php picture_count() ; ?>">

    I want to call the function picture_count() when button labeled "Add another
    picture" is clicked in HTML

    I do not want to use submit in place of button since I do not want to submit
    the form at this time.

    With the above statement, I receive an error expected ";" and the function
    is not called.

    Thanks!


  • Stephen Gordon

    #2
    Re: onClick

    Ken wrote:[color=blue]
    > Does php work with onClick in an html input statement?
    >
    > <HTML>
    > <input type="button" name="add_pictu re" value="Add another picture"
    > onClick="<?php picture_count() ; ?>">
    >
    > I want to call the function picture_count() when button labeled "Add another
    > picture" is clicked in HTML
    >
    > I do not want to use submit in place of button since I do not want to submit
    > the form at this time.
    >
    > With the above statement, I receive an error expected ";" and the function
    > is not called.
    >
    > Thanks!
    >
    >[/color]

    The function will not be called because:

    A) PHP is serverside whereas the onclick event you are trying to catch
    is client side.

    B) the onclick attribute is (to my knowledge) expected to refer to a
    javascript function/statement.

    From what you've posted I can't tell exactly what is supposed to be
    done when the user clicks the button (ie. what your function does) but
    maybe you can consider using some javascript to reload the page and
    update whatever your function was updating.

    -Steve

    Comment

    • Reply Via Newsgroup

      #3
      Re: onClick

      Ken wrote:
      [color=blue]
      > Does php work with onClick in an html input statement?
      >
      > <HTML>
      > <input type="button" name="add_pictu re" value="Add another picture"
      > onClick="<?php picture_count() ; ?>">
      >
      > I want to call the function picture_count() when button labeled "Add another
      > picture" is clicked in HTML
      >
      > I do not want to use submit in place of button since I do not want to submit
      > the form at this time.
      >
      > With the above statement, I receive an error expected ";" and the function
      > is not called.
      >
      > Thanks!
      >
      >[/color]


      You are mixing two different technologies together... PHP is server side
      - The onClick event is client side... This means that your PHP code is
      parsed/run BEFORE it gets to the user/client side.

      If PHP is correctly configured on your server, then view the page where
      you have the above code - My bet is that in the 'onClick' event, you
      will NOT see <?php picture_count() ; ?> but instead see the result of
      picture_count() - And unless you manage to store the value/result of
      picture_count somewhere on your server, then I'd guess that the value
      will always be the same, no matter how many uploads you did.

      Chances are, someone in comp.lang.javas cript will (at least in part)
      help you towards a solution...

      laters
      randelld

      Comment

      Working...