cobbossee Posted November 12, 2010 Report Share Posted November 12, 2010 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. Quote Link to comment Share on other sites More sharing options...
nkamalan Posted November 12, 2010 Report Share Posted November 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
cobbossee Posted November 12, 2010 Author Report Share Posted November 12, 2010 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 ; Quote Link to comment Share on other sites More sharing options...
nkamalan Posted November 12, 2010 Report Share Posted November 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
cobbossee Posted November 12, 2010 Author Report Share Posted November 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
bahar_vm Posted November 13, 2010 Report Share Posted November 13, 2010 The code should go to an HTML block at the bottom of DataPage Elements. Insert an HTML block the same way you inserted Header/Footer and write the code inside the block, make sure to move the block to the end of the fields list (Elements). Best, Bahar M. Quote Link to comment Share on other sites More sharing options...
cobbossee Posted November 13, 2010 Author Report Share Posted November 13, 2010 Perfect! Thanks you both for your help. Quote Link to comment Share on other sites More sharing options...
cobbossee Posted November 13, 2010 Author Report Share Posted November 13, 2010 One more question... Can you use the same script to insert a parameter that is being passed to this form from a previous form? Quote Link to comment Share on other sites More sharing options...
bahar_vm Posted November 17, 2010 Report Share Posted November 17, 2010 The code might be different in that case. When you use InsertRecord or EditRecord you are referring to the input value of the data entry, editable, or hidden fields in a Web Form or Update Form. Best, Bahar M. 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.