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 10 of 10
  1. #1
    Junior Member
    Join Date
    Mar 2005
    Location
    edinburgh
    Posts
    12
    Member #
    9464
    okay does anybody know how I can send some info using javascript to a php page without using an image?

    I want soemthing like
    <a href="whatever" onlick='something('whatever')>hello</a>

    I would like the javascript to then send info to a php page?

    thanks
    Phil.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Sure.

    Using the GET superglobal.. I will use JavaScript to write the url.

    Code:
    <script type="text/javascript">
    
    document.write("<a href=\"page.php?var=value&var2=value2\">link text</a>");
    
    </script>
    Then, you can either set variables to them in PHP singulary, like
    PHP Code:
    <?php
    // this is page.php
    $var $_GET['var'];
    $var2 $_GET['var2'];
    ?>
    Or use a loop to output them:
    PHP Code:
    <?php
    foreach($_GET AS $key => $value)
        {
           echo 
    "$key : $value";
        }
    ?>

  4. #3
    Senior Member echoSwe's Avatar
    Join Date
    May 2004
    Posts
    332
    Member #
    5926
    This reloads the page which makes it utterly ineffecient to use javascript to click a link - why on earth would u write out a link with javascript??!?! Really bad solution, that one above.

    No, if you want to communicate with the server without making a postback - use ajax. Ranked. Top, most relevant to you.
    1. http://jibbering.com/2002/4/httprequest.html
    2. http://jedisthlm.com/2005/03/11/ajax-resources/
    3. http://prototype.conio.net/

  5. #4
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Well, this is in the JavaScript forum, and I presumed it would be JavaScriot variables that would be being passed to and from page. Good examples though

  6. #5
    Senior Member echoSwe's Avatar
    Join Date
    May 2004
    Posts
    332
    Member #
    5926
    XmlHttpRequest is javascript!

  7. #6
    Junior Member
    Join Date
    Mar 2005
    Location
    edinburgh
    Posts
    12
    Member #
    9464
    thanks for those links, I have kinda got it working now.

  8. #7
    Senior Member echoSwe's Avatar
    Join Date
    May 2004
    Posts
    332
    Member #
    5926
    Great! What solution did you opt for?

  9. #8
    Senior Member
    Join Date
    Feb 2005
    Location
    Canada
    Posts
    435
    Member #
    8983
    if you are building links with javascript put it into the file so that it is like a function:
    HTML Code:
    <a href="javascript:somefunction('link?this=that...')">
    Code:
    function somefunction(url)
    {
    window.location = url
    }
    hope this helps...
    Thee Pyro Wolf

  10. #9
    Senior Member Stylise's Avatar
    Join Date
    Jul 2005
    Location
    Mount Martha, Australia
    Posts
    229
    Member #
    10679
    Yeah, like echoSwe has said, the only way to do this is with AJAX. I highly recommend prototype, esp when it's used with scriptaculous

  11. #10
    Senior Member echoSwe's Avatar
    Join Date
    May 2004
    Posts
    332
    Member #
    5926
    Quote Originally Posted by pyrodragon
    if you are building links with javascript put it into the file so that it is like a function:
    HTML Code:
    <a href="javascript:somefunction('link?this=that...')">
    Code:
    function somefunction(url)
    {
    window.location = url
    }
    hope this helps...
    If you do that it won't degrade if you turn off javascript!
    <a href="thisFile.aspx?id=3" title="Click me!" onclick="somefunction(this.href);return false;">Text</a>


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 11:30 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com