Jump to content


Photo

OnClick set Var Function..


  • Please log in to reply
3 replies to this topic

#1 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 11 August 2006 - 02:46 AM

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!

#2 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 11 August 2006 - 02:53 AM

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.
<a href="javascript:document.forms[0].some_click_flag.value=1;">your picture</a>
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.

#3 BaconBeast321

BaconBeast321
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 11 August 2006 - 03:03 AM

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"];




#4 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 14 August 2006 - 02:49 AM

your form can look like this-
<form enctype="multipart/form-data" method="post">
<input type="hidden" name="click" value=""></form>

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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users