Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    href...two things at once

    Hey, does anyone know of a way to get a href link to do two things at once? Say when the user clicks the link it not only calls a PHP function, but does something else with the same click?

    Code:
    <a href='indexphp.php?act=generate_quotes' >Generate</a></div>
    Code:
    <a href="#" onclick="document.getElementById('myStyle').style.display = 'block';return false">Darken Page</a>
    There are the two things I'm trying to make the link do, if anyone has any information I'd be very greatful,

    thanks.

    p.s - Javascripts kind of out of the question. So if anyone knows any alternative methods that'd be great.
    Last edited by wacom; 08-14-2010 at 06:53 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    That doesn't quite make sense to me. You say javascript is out of the question, but this:

    Code:
    <a href="#" onclick="document.getElementById('myStyle').style.display = 'block';return false">Darken Page</a>
    is javascript.

    This would be relatively straightforward with javascript.

  • #3
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry, my mistake, I posted the wrong link. The link calling the PHP remainds the same, and the other should just be a simple href link.

    Is it possible without using javascript? If not I'll have to use it, but I wanted to try and get away without.

    sorry for the confusion

  • #4
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    What exactly is it that needs to happen if the user clicks on the link - it seems like they need to go to two places - or do they in fact need to generate a quote via your php script and then end up on a different page?

    If the latter then depending upon the quote generation and what's required, that php script could redirect to the new page once the rest of the script's completed.

  • #5
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    What exactly is it that needs to happen if the user clicks on the link - it seems like they need to go to two places - or do they in fact need to generate a quote via your php script and then end up on a different page?

    If the latter then depending upon the quote generation and what's required, that php script could redirect to the new page once the rest of the script's completed.
    What I'm trying to basically when the users is generating the quotes from the database, the screen is dimmed, so I want the user to click the link, so the screen goes dark AND generate the first quote...

    So:

    user clicks link : screen darkens + first quote generated

    Then the user can cycle through the quotes with a dimmed screen

    if that makes sense?

    So anyway of combining

    <div id="lb1" class="lb"><a href="#top"><img src="1.png" alt="oh man" /></a></div>

    With

    <a href='indexphp.php?act=generate_quotes' >Generate</a></div>
    Last edited by wacom; 08-15-2010 at 11:05 AM.

  • #6
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    If the user doesn't actually go to the generate quotes php page, and you want them to stay on the page while you call the script in the background, then you'd need to do this with AJAX.

    Your other alternative is to have the generate script send the user back to the calling page, but then the screen would refresh while the quote is being generated, rather than dim.

  • #7
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    If the user doesn't actually go to the generate quotes php page, and you want them to stay on the page while you call the script in the background, then you'd need to do this with AJAX.

    Your other alternative is to have the generate script send the user back to the calling page, but then the screen would refresh while the quote is being generated, rather than dim.
    The user shall already be on the php page. The link simple calls the function from the same page. Just wondered if I could get it to dim while the user was generating the quotes from the database

  • #8
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    OK, that's not clear from your code alone - so at the moment your page is refreshing when you click the generate link? I think you're back to using javascript then - once the "generate quote" is clicked you could dim your page, then use AJAX to call the script again without refreshing your page, and undim once the response is received.

  • #9
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    OK, that's not clear from your code alone - so at the moment your page is refreshing when you click the generate link? I think you're back to using javascript then - once the "generate quote" is clicked you could dim your page, then use AJAX to call the script again without refreshing your page, and undim once the response is received.
    I'm calling the quotes via php, there's no javascript involved in my page thus far. I'll post the php function here with the link:

    Code:
    <?php
    
    if($_GET['act'] == "generate_quotes") {
    
    $con = mysql_connect("*", "*", "*");
    if (!$con)
    
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("quote", $con);
    
    $result = mysql_query( " SELECT * FROM `quote`  ORDER BY RAND() LIMIT 0,1 " );
    
    while($row = mysql_fetch_array($result))
    
      {
      echo '<span class="pink">' . $row['q_quote'] . "</span>";
      }
    
    echo "</table>";
    
    mysql_close($con);
    
    } else { 
    
    echo "<img src=\"vpbgt.png\">";
    
    }
    ?>
    Code:
    <div><a href="indexphp.php?act=generate_quotes">Generate</a></div>
    /\ The entire PHP [no javascript]

    I want the try and make the link I posted ALSO do this:

    Code:
    <div id="lb1" class="lb"><a href="#top"><img src="1.png" alt="oh man" /></a></div>

  • #10
    Senior Coder
    Join Date
    Feb 2009
    Location
    Ilkley, West Yorkshire, UK
    Posts
    2,955
    Thanks
    9
    Thanked 726 Times in 720 Posts
    Quote Originally Posted by wacom View Post
    I'm calling the quotes via php, there's no javascript involved in my page thus far.
    Yes, I know.

    I'm guessing at a few things here, but assuming that you have a page which allows a user to request a quote, and then the quote is displayed on the same page after the page refreshes, and that the #lb1 div is the one that causes the dimming?

    If that's right, then you could include the #lb1 only if a quote has been requested via your php code, so it would then show on the page - but it would then remain there unless you employ some javascript to remove it or refresh the page again.

  • #11
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by SB65 View Post
    Yes, I know.

    I'm guessing at a few things here, but assuming that you have a page which allows a user to request a quote, and then the quote is displayed on the same page after the page refreshes, and that the #lb1 div is the one that causes the dimming?
    Your right with whats doing what, but the site doesn't require a page refresh, the PHP changes the quote dynamically on the page, to avoid a page refresh.

    Code:
    If that's right, then you could include the #lb1 only if a quote has been requested via your php code, so it would then show on the page - but it would then remain there unless you employ some javascript to remove it or refresh the page again.
    Which part do you mean would remain there? The dimmed page?

    Ill show you the dimmed page effect to maybe clear any confusion:

    http://www.studiomoh.com/fun/csslightbox/

  • #12
    Regular Coder
    Join Date
    Jul 2010
    Location
    St George, UT
    Posts
    138
    Thanks
    6
    Thanked 17 Times in 17 Posts
    Just use AJAX. There is no other way to asynchronously make a call to the server while doing something else. It's just not possible.

    AJAX is your friend.

    Exceeding simple AJAX example

    OR!! Download MooTools and put this code in your header:

    Code:
    function easyAjax() {
      url = 'index.php';
      new Request({
        url: url,
        method: 'get',
        onSuccess: function(responseText) {
          //responseText is what is returned from url
          alert("OMG YOU KNOW AJAX!");
         }
      }).send();
    }

  • #13
    New Coder
    Join Date
    Aug 2010
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the reply and the links. Can I just ask if there's anyway the function could handle the other effect, so all the link would do was call the function?

    Something like:

    Code:
    <?php
    
    if($_GET['act'] == "generate_quotes") {
    
    $con = mysql_connect("*", "*", "*");
    if (!$con)
    
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("quote", $con);
    
    $result = mysql_query( " SELECT * FROM `quote`  ORDER BY RAND() LIMIT 0,1 " );
    
    while($row = mysql_fetch_array($result))
    
      {
      echo '<span class="pink">' . $row['q_quote'] . "</span>";
      }
    
    echo "</table>";
    
    mysql_close($con);
    
    
    
    // Darken screen link in here somehow?
    
    
    } else { 
    
    echo "<img src=\"vpbgt.png\">";
    
    }
    ?>
    It may not be possible, but just a thought.


  •  

    Posting Permissions

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