Jump to content

Archived

This topic is now archived and is closed to further replies.

BaconBeast321

OnClick set Var Function..

Recommended Posts

Hi there, I want to be able to set a OnClick for a picture that runs a function that makes a variable = 1..
How do I go about doing this? I know how to do it in javascript, but this needs to be PHP.

Essentially it is for the manager of the site, he can click on a button which adds like a linebreak '<BR>' or something
into the news report he is making...

Have tried looking around for solutions but cant find any, help much appreciated!

Share this post


Link to post
Share on other sites
PHP can't do anything with onCLick unless there is a javascript function that sets the value of a form input that is then submitted to the server.

e.g.
[code]
<a href="javascript:document.forms[0].some_click_flag.value=1;">your picture</a>
[/code]
then only when forms[0] is submitted will the server get some_click_flag and know that the picture was clicked.

Perhaps you want the user to click and send stuff to the server without having to reload your page.  To do that, you can set upa hidden frame that holds forms with hidden inputs that are sumitted when the user clicks photos in the visible frame.

Share this post


Link to post
Share on other sites
so for the hidden form solution.... hows this... :

<form enctype="multipart/form-data" method="post">

<input type="hidden" name="click" value="<img src="pictobeclicked.jpg">">
</form>

then

$vartobeset = $_POST["clickme"];


Share this post


Link to post
Share on other sites
your form can look like this-
[code]
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="click" value=""></form>
[/code]

and then in the HTML of your page, the image will look like this:
[code]
<img src="pictobeclicked.jpg" onClick="document.forms[0].click.value=1;document.forms[0].submit();">
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.