Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Junior Member
    Join Date
    Apr 2005
    Location
    London
    Posts
    4
    Member #
    9609
    Hey

    I want to execute an SQL query in PHP when a checkbox is clicked. There is an onClick event but doesn't seem to execute a PHP segment in there.

    e.g.
    <form action="" method="get"><input name="" type="checkbox" onClick="<?php echo 'hello world'; ?>" value="" /></form>

    Is there anyway of calling php from an onClick event??

    Thanks for any help in advance.
    William.

  2.  

  3. #2
    Senior Member Fallout's Avatar
    Join Date
    Aug 2003
    Location
    Richmond, Virginia
    Posts
    543
    Member #
    2748
    No, javascript is a client-side language... so the server-side PHP will execute before it gets to the javascript. If you view the source of your page you will see:

    Code:
    <form ... onClick="hello word">
    Which, of course, doesn't do anything.

  4. #3
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    It can be done...

    You will need to use the AJAX model which will enable you to call server side PHP code from Javascript.

    See here for an overview http://www.adaptivepath.com/publicat...ves/000385.php

    I mentioned this on another thread a few days back (co-incidence, eh!) but there's a set of libraries called SAJAX which will help you on your way...

    The website is at http://www.modernmethod.com/sajax/

    What you do with SAJAX is "export" your php functions server-side and then Javascript will be able to see them... you can then call them just as you would any other Javascript function.

    Good luck!

    Sean

  5. #4
    Senior Member rosland's Avatar
    Join Date
    Jul 2003
    Location
    Norway
    Posts
    1,944
    Member #
    2096
    Isn't there a function in javascript that talks to the server?

    .....onChange="this.form.submit()">
    S. Rosland

  6. #5
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    Well, that would actually submit the form and, by consequence, change the page. This isn't necessarily a bad thing, even less so if you have the form submit into an invisible iframe or something to handle the submission without changing the page.

    Invisible iframes, btw, are what I consider to be the poor man's AJAX :-D.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:54 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com