Solved

How do you display a checked a radio button data from the table into a form when the field is 'YES'

Posted on 2013-06-13
5
639 Views
Last Modified: 2013-07-03
Hello,

I have a ColdFusion form and SQL Database.   It's working fine. So when the user login, i'm able to display his data from the table into a textarea but I wasn't able to display the radio button checked and checkbox button checked.

so let start with the radio button and I will post another question for the checkbox.

reading_yes --> My form, when i load my form into my browser it show "YES" instead of the button checked
                                    (X) yes ( )no

This is the code.

 <td colspan="2" height="5" width="100%"><cfoutput>#DisplayCVIToolvolunteer.contactme#<cfinput type="radio" name="contactMe" id="contactMeYes" value="Yes" required="true" message="Question 1: This field is required. Please select yes or no. Please try again." onClick="checkme(this);" />
                &nbsp;
                <label for="ContactMeYes">Yes</label>
                <cfinput type="radio" name="contactMe" id="contactMeNo" value="No" onClick="checkme(this);" />
                No
                </label>
                &nbsp;&nbsp;<br>
                <div id="specify" style="display:none;">
                  <label>Please specify:
                    <input type="text" name="ContactMeSpecify" id="ContactMeSpecify" value="" maxlength="255" size="30" style="width: 200px;border:red 1px solid;">
                  </label>
                  <p id="error" style="color:red;display:none;">Required input! Or else... click "No" above...</p>
                </div></cfoutput></td>

Open in new window

SQL-Table-data.jpg
display-data.jpg
reading-yes.jpg
0
Comment
Question by:koila
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39245936
Use cfinput's "checked" attribute:

<cfinput type="radio" name="contactMe" value="Yes"
      checked="#DisplayCVIToolvolunteer.contactme eq 'Yes'#" ..../>  Yes
<cfinput type="radio" name="contactMe" value="No"
      checked="#DisplayCVIToolvolunteer.contactme eq 'no'#" ..../>  No
0
 
LVL 4

Author Comment

by:koila
ID: 39248241
Hello Agx,

Thank you for your note, I've add the code and I've loaded the form so the yes button didn't came checked according to the table entry? why.

(*) yes (no)

The contactme field char10, not null

contactme
Yes

Thank you for your time,
0
 
LVL 4

Author Comment

by:koila
ID: 39248247
this is my code

<table border="0" cellspacing="0" cellpadding="0" width="100%" class="qtable">
            <tr>
              <td colspan="2" height="5" width="100%"><cfinput type="radio" name="contactMe" id="contactMeYes" value="Yes" checked="#DisplayCVIToolvolunteer.contactme eq 'Yes'#" required="true" message="Question 1: This field is required. Please select yes or no. Please try again." onClick="checkme(this);" />
                &nbsp;
                <label for="ContactMeYes">Yes</label>
                <cfinput type="radio" name="contactMe" id="contactMeNo" value="No" checked="#DisplayCVIToolvolunteer.contactme eq 'no'#" onClick="checkme(this);" />
                No
                </label>
                &nbsp;&nbsp;<br>
                <div id="specify" style="display:none;">
                  <label>Please specify:
                    <input type="text" name="ContactMeSpecify" id="ContactMeSpecify" value="" maxlength="255" size="30" style="width: 200px;border:red 1px solid;">
                  </label>
                  <p id="error" style="color:red;display:none;">Required input! Or else... click "No" above...</p>
                </div></td>
            </tr>
          </table>

Open in new window

0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39248925
> The contactme field char10, not null

The only values in that column are "YES" or "NO", right?  

It could be that it's a CHAR field.  That'll add extra spaces to the query value.  Try trimming the value first:

<cfset trimmedValue = trim(DisplayCVIToolvolunteer.contactme)>
<cfoutput>
Debug:  #trimmedValue#  Length = #len(trimmedValue)#<br>
</cfoutput>
<cfinput type="radio" name="contactMe" value="Yes"
      checked="#trimmedValue eq 'Yes'#" ..../>  Yes
<cfinput type="radio" name="contactMe" value="No"
      checked="#trimmedValue eq 'no'#" ..../>  No


BTW: CHAR is a good choice when the values are always the same fixed size. For example, for storing UUID's. If the value lengths can vary, VARCHAR is usually a better choice.
0
 
LVL 4

Author Comment

by:koila
ID: 39297430
thank you.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
recordcount is coming as undefined in query 4 67
ColdFusion MS SQL CSV Impport 10 69
Can I run Access database.exe file thru Coldfusion 2 141
CSS HELP 6 93
This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question