...

View Full Version : href...two things at once



wacom
08-14-2010, 06:40 PM
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?



<a href='indexphp.php?act=generate_quotes' >Generate</a></div>




<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.

SB65
08-14-2010, 07:38 PM
That doesn't quite make sense to me. You say javascript is out of the question, but this:


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

is javascript.

This would be relatively straightforward with javascript.

wacom
08-14-2010, 08:01 PM
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

SB65
08-15-2010, 08:14 AM
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.

wacom
08-15-2010, 10:58 AM
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>

SB65
08-15-2010, 11:15 AM
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.

wacom
08-15-2010, 11:50 AM
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

SB65
08-15-2010, 12:16 PM
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.

wacom
08-15-2010, 12:22 PM
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:



<?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\">";

}
?>



<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:



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

SB65
08-15-2010, 12:41 PM
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.

wacom
08-15-2010, 12:50 PM
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.



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/

wildreason
08-15-2010, 06:03 PM
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 (http://weblogs.asp.net/jstengel/archive/2008/01/24/a-simple-ajax-example-for-the-add-developer.aspx)

OR!! Download MooTools (http://mootools.net/download) and put this code in your header:



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();
}

wacom
08-15-2010, 06:40 PM
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:



<?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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum