Jump to content
Sign in to follow this  
abelphathost

Updating a field basing on status of a checkbox

Recommended Posts

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>

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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>

 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...