Jump to content

onclick action with checkbox


Recommended Posts

I'm a novice(at best) on programming.

I have a form where I have users click on a checkbox and I would like to be able to update a field with a fixed value based on them checking it.

The field is in the database, but is hidden as it's used later as a number/currency field.

Any help on this would be great. I have not programmed with JS before.

Thanks. :D

Link to comment
Share on other sites

Hello, 

 

If it is in a webform you can add a Header/Footer and paste something like:

 



      var o_checkbox = document.getElementById("InsertRecordFIELDNAME1") ;
      
      function f_event(){
            if (o_checkbox.checked) {
                  document.getElementById("InsertRecordFIELDNAME2").value = "XXXX";
            } else {
                  document.getElementById("InsertRecordFIELDNAME2").value = "YYYY" ;
            }
      }
      o_checkbox.onclick = f_event ;


FIELDNAME1 is the checkbox filed name and FIELDNAME2 is the name of field that you want to change the value.

 

Regards,

Nkamalan

Link to comment
Share on other sites

I tried the code you provided and added the two fields in:

 

Checkbox - Camper_Cap

Value - Camper_CAP_Value

 

My goal is that if somebody checks Camper_Cap that the value of 250 goes into Camper_CAP_Value otherwise it's null.

 

Did I do something wrong on this code?

 



var o_checkbox = document.getElementById("InsertRecordCamper_Cap") ;


function f_event(){
if (o_checkbox.checked) {
document.getElementById("InsertRecordCamper_CAP_Price").value = "250"
} else {
document.getElementById("InsertRecordCamper_CAP_Price").value = "" ;
}
}
o_checkbox.onclick = f_event ;

Link to comment
Share on other sites

A semicolon at the end of this line:

document.getElementById("InsertRecordCamper_CAP_Price").value = "250";

Is it in a submission form or an update form? If it is in an update form then change these lines to :

var o_checkbox = document.getElementById("EditRecordCamper_Cap") ;

document.getElementById("EditRecordCamper_CAP_Price").value = "250";

document.getElementById("EditRecordCamper_CAP_Price").value = "" ;

Regards,

NKamalan

Link to comment
Share on other sites

i updated it with the ";" and still doesn't work.

I have this code in the Header, just to verify.

I am doing a submit form. I setup a separate test table with test form with 2 fields to do this and it didn't work either.

Any other thoughts? Sorry, i don't have a programming background. If you need other information, please advise.

Thanks

Link to comment
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...
×
×
  • Create New...