Jump to content
  • 0

Fill field with value based on another fields value


Question

I know this has been done in several variations with list boxes and autocomplete. But I cant get it to fire in my scenario.  Possibly because Im trying to accomplish this with same table/DP?

Two fields A and B. 

Field A is Yes/No.  B is hidden waiting to receive a value.

If A=Yes, hidden field B should be completed with value "candidate".

Simple, but alluding me.

Triggered action, calculated field or passed parameter?

Hoping not to have a separate table just for this option, only to put it back in there with a view.

 

 

Link to post
Share on other sites

12 answers to this question

Recommended Posts

  • 0

(1) Create a test app.

(2) In that app - Create a table named "testtbl" with 2 data fields: "radioselect" and "hiddenfield" and save the table.

(3) Create a data page for a form, and use "testtbl" as your "Select data source".

(4) Add the 2 data fields "radioselect" and "hiddenfield"  into your input form - then create 2 radio buttons for the "radioselect" data field, applying "yes" value to one and "no" value to the other.

(5) Set the data field value "hiddenfield" to "hidden". (you can test by not hiding it right away).

(6) Also add a HEADER and FOOTER to the data page form, paste the code below into the header and save.

(7) Preview the data page form, select any radio button, hit submit. Check your data table for the correct data submission .. if it doesn't work come back and let me know what's what.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
$(function () {
   

 $("input[name=InsertRecordradioselect]:radio").click(function () {

        if ($('input[name=InsertRecordradioselect]:checked').val() == "yes") {
            
$('#InsertRecordhiddenfield').val("candidate");
        } else if ($('input[name=InsertRecordradioselect]:checked').val() == "no") {
            
$('#InsertRecordhiddenfield').val("no");
        }

});

});

</script>

Best.

 

Geoff

Link to post
Share on other sites
  • 0
3 minutes ago, geoffdude said:

The answer is provided above ... if you want to use a checkbox, then just change the radio buttons in my example to a checkbox.

 


$("input[name=InsertRecordradioselect]:radio").click(function

change to:


$("input[name=InsertRecordradioselect]:checkbox").click(function

 

ok thanks.  just wanted to see directrix's solution as well.  exact same?

Link to post
Share on other sites
  • 0

Here's the modified script for a checkbox .. using the same data table from initial example, but changing your form field "radioselect" to an actual checkbox. Keeping the name is fine."

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
   

 $("input[name=InsertRecordradioselect]:checkbox").click(function () {

        if ($('input[name=InsertRecordradioselect]:checked').val() == "yes") {
            
$('#InsertRecordhiddenfield').val("candidate");
        } else   {
            
$('#InsertRecordhiddenfield').val("");
        }

});

});

</script>

 

Link to post
Share on other sites
  • 0
14 minutes ago, directrix said:

Hello @roattw,

I simply used Rules to hide field B onload and disabled it first. When Field A is checked, then Field B will come up. And also, putting an onload parameter value in Field B: http://prntscr.com/ly1ek9. If you want your Field B stay hidden, then you may used simple CSS of JavaScript.

Thank you.  Simple solution.  Will try both.

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