Jump to content
  • 0

Update text field based on radio button selections


thirdcircle
 Share

Question

Objective: On submission of a web update form, write "Yes" or "No" to a text field based on the selections made to three different radio buttons in the same form.

Radio button 1 (text field name = Question 1): values are "YES" or "NO"

Radio button 2 (text field name = Question 2): values are "YES" or "NO"

Radio button 3 (text field name = Question 3): values are "YES" or "NO"

The field named "user_profile_complete" is a Text Field (255).

The text field "user_profile_complete" should be updated to say "Yes" if all three radio buttons were selected "NO."

If any of the three radio buttons were selected "Yes" then the text field "user_profile_complete" should be updated to say "No."

This is a single record update form.

Below is Javascript I have written to accomplish this task but it is not working. I have this script placed in the footer of the Datapage containing all the elements listed above.

Please help.

________________________________________

function setcomplete()

{

var q1 = document.getElementById("EditRecordQuestion_1").value;

var q2 = document.getElementById("EditRecordQuestion_2").value;

var q3 = document.getElementById("EditRecordQuestion_3").value;

var y = "Yes"

var n = "No"

if (q1 == 'NO') && (q2 == 'NO') && (q3 == 'NO')

{

document.getElementById("EditRecorduser_profile_complete").value=y;

}

else

{

document.getElementById("EditRecorduser_profile_complete").value=n;

}

}

/* On submitting the webform, the function setcomplete is executed */

document.getElementById("caspioform").onsubmit=setcomplete;

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello, thirdcircle

Your problem is that you're using code of Text Field for Radio Buttons.

For radio buttons, each radio option has its own unique ID, and you should just check the 'checked' attribute, not value.

I've prepared a piece of code that may help you.

Into one HTML block paste the following

function testAlert_Question_10()

{

return document.getElementById("EditRecordQuestion_10").checked;

}

function testAlert_Question_11()

{

return document.getElementById("EditRecordQuestion_11").checked;

}

To test this part I've added another HTML block with two testAlert_Question_10

testAlert_Question_11

Think you understand that testAlert_Question_11() returned 'true' in case option (YES or NO) is selected and 'false' in case option isn't selected.

Link to comment
Share on other sites

  • 0

 

Hi @thirdcircle,

You could use Calculated Value on this and have a formula of CASE WHEN. Caspio introduced new features which you can find here: https://howto.caspio.com/release-notes/caspio-bridge-13-0/ This release includes a new feature, Calculated Values in Submission Forms.  This allows you to generate calculations which you can use for your text field. 

Check these videos for more information:

I hope this helps!

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

×
×
  • Create New...