MetroidMaster1914 Posted June 26, 2008 Share Posted June 26, 2008 I'm trying to code a skin selector for my website, and I'm having trouble changing a cookie when selecting from a select form. Basically what I want to do is something thing like this: <form> <select onChange='<?php setcookie(MHQ_skin, selectedvaluehere, time()+(60*60*24*365)); ?>;window.location.reload();'> <option value='3year'> 3rd Anniversary Skin <option value='orig'> Original Skin </select> </form> Is there anyway way that that's possible? Let me know if you need more info. (I know that code won't work.) Link to comment https://forums.phpfreaks.com/topic/111956-solved-using-onchange-with-php/ Share on other sites More sharing options...
trq Posted June 26, 2008 Share Posted June 26, 2008 OnChange is a client side event, php runs server side. The best you can do is set the OnChange event to execute a Javascript function which in turn calls the XMLHttpRequest object which can make a request to the server and execute your php code. This methodology is the basis of Ajax, and that my good friend is where you want to start looking. Link to comment https://forums.phpfreaks.com/topic/111956-solved-using-onchange-with-php/#findComment-574651 Share on other sites More sharing options...
bluejay002 Posted June 26, 2008 Share Posted June 26, 2008 OnChange is a client side event, php runs server side. The best you can do is set the OnChange event to execute a Javascript function which in turn calls the XMLHttpRequest object which can make a request to the server and execute your php code. This methodology is the basis of Ajax, and that my good friend is where you want to start looking. Definitely... or if you are not interested with Ajax as of the moment... then reload the page with a value submitted, giving the new skin to take effect. Link to comment https://forums.phpfreaks.com/topic/111956-solved-using-onchange-with-php/#findComment-574708 Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Share Posted June 26, 2008 I would avoid using AJAX in this situation because you have to reload the page once the cookie is set anyways for it to come into effect. This is how I do it: <? if ($_POST['submit']) { setcookie(MHQ_skin, $_POST[skin], time()+(60*60*24*365)); header('location:somepage.php'); } ?> <form action="" method="post"> <select name="skin"> <option value='3year'>3rd Anniversary Skin</option> <option value='orig'>Original Skin</option> </select> <input type="submit" value="submit" name="submit" /> </form> Link to comment https://forums.phpfreaks.com/topic/111956-solved-using-onchange-with-php/#findComment-574742 Share on other sites More sharing options...
bluejay002 Posted June 26, 2008 Share Posted June 26, 2008 well, most sites do use page reload in terms of skinning instead of Ajax. Well, if I will be asked how will I do it... I will use page reload also. Link to comment https://forums.phpfreaks.com/topic/111956-solved-using-onchange-with-php/#findComment-574770 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.