Jump to content
  • 0
ezIQchad

Javascript onsubmit and Checkboxes

Question

Hi @abelphathost,

Thanks for the message, but let's not ask questions privately.... the point of a forum is for people to find that somebody else has already asked the same question.

 

Quote

 

Hi, Hope you are fine,

 

May you please help me out. I am having a serious problem with what I want to achieve here. I want to update a database field named status and change it's value to approved when a checkbox is checked or leave it as pending when the checkbox is not checked. here is my code:

 

<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")="pending";
}
document.getElementById("caspioform").onsubmit= Updatestatus;
 
</SCRIPT>

 

its not doing anything i don't know where I am wrong. please assist

 

A couple things to note

1 - I've had trouble using JS and Caspio's checkboxes. Dropdowns are easier to work with.

 

2 - I never use 'onsubmit'. Rather i create a fake submit button that runs that code I need before the submit happens then wrap the function with: document.getElementById("Submit").click()

 

** If you must have something easier than a dropdown...

 This takes some work, but will allow you to do it.

 

HTML block

<style>

#YOUR_FIELD_ID {display: none}

.fake-radio {

  width: 120px;

 height: 50px;

 padding: 16px;

 margin: 16px 0 0 32px; 

font-size: 18px;

 float: left;

}

</style>

 

<div class="fake-radio" onclick="document.getElementsByName('YOUR_FIELD_ID')[0].value = 'Yes';>Yes</div>

 

<div class="fake-radio" onclick="document.getElementsByName('InsertRecordFieldName')[0].value = 'No';>No</div>

 

 

YOUR_FIELD_ID

1. right click the field you want to populate > inspect

2. Look for <xx class="sample" id="XYZ_98sd7d" name="InsertRecordYOURFIELDNAME">Hi World</xx>

3. your answer is InsertRecordYOURFIELDNAME

 

Try these suggestions and I'm sure you'll find your solution

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

thanks for the response, however I have implemented your suggestion, but am still struggling to get my javascript yield anything positive. I have changed my status field to a dropdown with options such that when a user select a certain option the status will change. I know that I can use a cascading textfield but i wanted a javascript solution. 

 

<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
  • 0

Hey abelphathot,

this might help..

In your original post, if its a checkbox



<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")="pending";
}
document.getElementById("caspioform").onsubmit= Updatestatus;
 
</SCRIPT>

 

you need to change to

 
function Updatestatus()
{
if (document.getElementById("approved").checked=true);
{
document.getElementById("InsertRecordstatus")="approved";
}
else if (document.getElementById("approved").checked=false);
{
document.getElementById("InsertRecordstatus")="pending";
}
document.getElementById("caspioform").onsubmit= Updatestatus;
 
</SCRIPT>

 

change from "==" to =

and

 

you were also missing some semicolons :)

 

Best ~

 

 

 

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
Answer this question...

×   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...

×
×
  • Create New...