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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

823 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