nade93 Posted March 16, 2010 Share Posted March 16, 2010 Hi All I am trying to update a database when a checkbox has been checked without using a submit button Please find code below: <form action="<? echo $PHP_SELF ; ?>" method="post" > <input type='checkbox' id="css_sized_container" name="checkbox[".$row['onoff']."]" value='<? echo $row['onoff']; ?>' onclick='document.form".$row['onoff'].".submit();' /> </form> <? include('../lib/conn.php'); $ifchecked = $_REQUEST['checkbox']; mysql_query("UPDATE users_audio SET onoff='' WHERE userid='1'"); ?> basically, i want the user to check or uncheck the box, this be passed to the database then the checkbox remembers the answer for that user from the database (i.e. $row['onoff']; ) Any help would be amaing as very stuck! Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/ Share on other sites More sharing options...
StathisG Posted March 16, 2010 Share Posted March 16, 2010 You can add a call to a JavaScript function using onclick="nameOfFunction()" within your checkbox (like you already do in a way). In that function you can make a request using Ajax to another php file and update the database there. Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/#findComment-1026999 Share on other sites More sharing options...
nade93 Posted March 16, 2010 Author Share Posted March 16, 2010 thanks for the reply, however i want to do it all on the same page without using ajax Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/#findComment-1027007 Share on other sites More sharing options...
StathisG Posted March 16, 2010 Share Posted March 16, 2010 If you don't have to use Ajax, you'll have to reload the page and submit the value of the checkbox to it. Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/#findComment-1027142 Share on other sites More sharing options...
nade93 Posted March 19, 2010 Author Share Posted March 19, 2010 how do i do it using ajax then as dont want to reload the page..... sorry just not very good with ajax..... well dont know any! Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/#findComment-1028560 Share on other sites More sharing options...
nade93 Posted March 22, 2010 Author Share Posted March 22, 2010 hey sorry to bump but can any one help me out please? thanks Quote Link to comment https://forums.phpfreaks.com/topic/195430-using-php-javascrip-to-pass-form-on-checkbox/#findComment-1029892 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.