Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. add a code to button on click/submit

add a code to button on click/submit

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    omlac
    wrote on last edited by
    #1

    Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards

    L M 2 Replies Last reply
    0
    • O omlac

      Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      JavaScript runs at the client side, where the button is. PHP runs at the server, and is unaware of someone clicking a button at the client side. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      R 1 Reply Last reply
      0
      • O omlac

        Hi all i would like to write an on click/submit event on a button and im doing it like this <form name="form1" action="" method="post"> <input type="button" name="mybutton" onclick="<?php print "my Test"; ?>"; form1.submit()"> </form> i know onclick is a javascript function,does anyone know what's the equivalent in PHP. Regards

        M Offline
        M Offline
        Marc Firth
        wrote on last edited by
        #3

        <?php if($_POST['submit']){ echo "form submitted"; } ?> <div id="mydiv">This is a div contents</div> <form name="form1" action="" method="post"> <input type="button" name="mybutton" id="mybutton" onclick="document.getElementById('mydiv').innerHTML = 'my Test'" value="fill div" /> <input type="submit" value="submit" name="submit" /> </form> The above code shows the difference between javascript & php. Javascript works on the page on the client side ("fill div" btn does not refresh the page). When you "submit" the form the contents of it are sent to the server. There the server sees that a form has been submitted and formats the page as required ( here it writes "form submitted to the beginning of the body text before sending it back to the client).

        Neonlight

        1 Reply Last reply
        0
        • L Luc Pattyn

          JavaScript runs at the client side, where the button is. PHP runs at the server, and is unaware of someone clicking a button at the client side. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


          R Offline
          R Offline
          Right Handed Monkey
          wrote on last edited by
          #4

          Right, basically there is no equivalent. PHP runs before the client sees the web page and only on the server. Javascript/VB run on the client side (browser) after the page has been processed by the PHP. That is why it is called PHP Hypertext Pre-processor.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups