abelphathost Posted February 21, 2017 Report Share Posted February 21, 2017 Hi everybody, i need to update a field i the database when a checkbox is checked here is my code but it's not working: <SCRIPT LANGUAGE="JavaScript"> function Updatestatus() { if (document.getElementById("approved").checked==true) { document.getElementById("status")="approved"; } else if (document.getElementById("approved").checked==false) { document.getElementById("status")="pend"; } document.getElementById("update as").onsubmit= UpdateQty; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Mathilda Posted February 22, 2017 Report Share Posted February 22, 2017 On 2/21/2017 at 4:53 AM, abelphathost said: Hi everybody, i need to update a field i the database when a checkbox is checked here is my code but it's not working: <SCRIPT LANGUAGE="JavaScript"> function Updatestatus() { if (document.getElementById("approved").checked==true) { document.getElementById("status")="approved"; } else if (document.getElementById("approved").checked==false) { document.getElementById("status")="pend"; } document.getElementById("update as").onsubmit= UpdateQty; </SCRIPT> Hi, I edited your code. I assume that you use details or update form. Try using the following code in the footer. <SCRIPT> function Updatestatus() { if (document.getElementById("EditRecordapproved").checked==true) { document.getElementById("EditRecordstatus").value="approved"; } else if (document.getElementById("EditRecordapproved").checked==false) { document.getElementById("EditRecordstatus").value="pend"; } } document.getElementById("caspioform").onsubmit = Updatestatus; </SCRIPT> You need to insert your field names in instead of approved and status, please note that Java Script is case sensitive. Also make sure that those fields are editable on the datapage. If you need to hide the status field, you may do that using html block Quote Link to comment Share on other sites More sharing options...
abelphathost Posted February 23, 2017 Author Report Share Posted February 23, 2017 Thanks Mathilda, however am still failing to get any positive result, I have tried to use a drop down list for selection of options but am still stuck. Maybe there is something that I have to do with for my javascript to execute. I am using the following script in my footer area as suggested: <SCRIPT LANGUAGE="JavaScript"> function Updatestatus() { if (document.getElementById("statuss").value=="Approve") { document.getElementById("status").value="approved"; } else if (document.getElementById("statuss").value=="Undecided") { document.getElementById("status").value="pending"; } document.getElementById("caspioform").onsubmit= Updatestatus; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Mathilda Posted February 23, 2017 Report Share Posted February 23, 2017 2 hours ago, abelphathost said: Thanks Mathilda, however am still failing to get any positive result, I have tried to use a drop down list for selection of options but am still stuck. Maybe there is something that I have to do with for my javascript to execute. I am using the following script in my footer area as suggested: <SCRIPT LANGUAGE="JavaScript"> function Updatestatus() { if (document.getElementById("statuss").value=="Approve") { document.getElementById("status").value="approved"; } else if (document.getElementById("statuss").value=="Undecided") { document.getElementById("status").value="pending"; } document.getElementById("caspioform").onsubmit= Updatestatus; </SCRIPT> You need use EditRecord syntax before field name, in my code the following name EditRecordapproved means that the EditRecord is a part of syntax and approved is a name of the field. So you need to insert your field names instead of mine, do not remove EditRecord. Also make sure that you hit "Source" button before inserting code in the footer. Terry 1 Quote Link to comment Share on other sites More sharing options...
abelphathost Posted February 23, 2017 Author Report Share Posted February 23, 2017 Thank you so much hey...........the code is perfect..... Quote Link to comment 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.
Note: Your post will require moderator approval before it will be visible.