BaconBeast321 Posted August 11, 2006 Share Posted August 11, 2006 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! Quote Link to comment https://forums.phpfreaks.com/topic/17201-onclick-set-var-function/ Share on other sites More sharing options...
bltesar Posted August 11, 2006 Share Posted August 11, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/17201-onclick-set-var-function/#findComment-72838 Share on other sites More sharing options...
BaconBeast321 Posted August 11, 2006 Author Share Posted August 11, 2006 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"]; Quote Link to comment https://forums.phpfreaks.com/topic/17201-onclick-set-var-function/#findComment-72841 Share on other sites More sharing options...
bltesar Posted August 14, 2006 Share Posted August 14, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/17201-onclick-set-var-function/#findComment-74300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.