Search code examples
coldfusioncoldfusion-11

Display data in HTML table or DataTable depending on radio button selection


I would like to give a user the option to display data in an HTML table or a DataTAble. I have a select dropdown that I am populating with a query output. After the user selects an option from the list they would select one of two radio buttons: (1) view HTML table, or (2) view DataTable. The user selects one of these radio buttons and then clicks on the submit button to display the results on a new page. The new page receives the form.value and inserts this into the query to produce the HTML table or DataTable.

I'm new to ColdFusion. It seems easier assign an action page to each radio button selection. I have made some attempt but nothing working yet. I'm guessing this may be a trivial task, but any help would be appreciated.

So on the form you would have your select dropdown and input

<select name="Species" class="dropdown">
<cfoutput query="species">
<option value="#species.Species#">#species.GenusSpecies#</option>
</cfoutput>
</select>    

<input type="radio" name="Species" value="DataTable"> DataTable
<input type="radio" name="Species" value="HTML" checked="checked"> HTML Table
<input type="submit" value="Submit" class="buttons"></input>

How do I assign something to a radio button and then execute with submit? cfparam or cflocation??

Thanks.


Solution

  • in 1st cfm from your example you do

    <body>
        <select name="Species" class="dropdown">
            <cfoutput query="species">
            <option value="#species.Species#">#species.GenusSpecies#</option>
            </cfoutput>
        </select>    
        <form action="Species.cfm" name="mainform">
            <input type="radio" name="Species" value="DataTable"/> DataTable
            <input type="radio" name="Species" value="HTML" checked="checked"/> HTML Table
            <input type="submit" value="Submit" class="buttons"/>
        </form>
    </body>
    

    on a separate cfm. let's say species.cfm you'd do

    <!---<cfdump var="#form#"> --->
    <cfif form.species eq 'DataTable'>
    
        display in datatables
    
    <cfelse>
        display in html
    </cfif>