how to pass parameters from form?
how to pass parameters from form?
natfoster
Posts: 1Questions: 1Answers: 0
Im using ajax to pass the data.
I made a form with a 'select' after clicking submit I would like to pass the value of statusvar and update the data.
<form method="post" class="form" role="form" id="sumittedForm" action="">
<select class="form-control" id="statusvar" name="statusvar" >
<option value="All" <cfif statusvar eq 'All'>selected</cfif>>All</option>
<option value="1" <cfif statusvar eq '1'>selected</cfif>>One</option>
<option value="2" <cfif statusvar eq '2'>selected</cfif>>Two</option>
</select>
<input type="submit" name="submit" id="validate" value="Submit" />
</form>
<script type="text/javascript" class="init">
$(document).ready(function() {
$('#example').DataTable({
"ajax": "showdata.cfc?method=getUsers",
"columns": [{
"data": "id"
}, {
"data": "questionone"
}]
});
});
</script>
this is my showdata.cfm
<cfcomponent output="no">
<cfsetting showdebugoutput="no" />
<cffunction name="getUsers" access="remote" returnformat="plain" returntype="any">
<cfset statusvar = "">
<cfquery name="getUsers" >
select top 100 * from thistable
where 1=1
<cfif statusvar neq '' >
and status = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="2" />
</cfif>
order by id desc
</cfquery>
<cfset resultStruct = Structnew() />
<cfset resultStuct["data"] = ArrayNew(1) />
<cfset count = 1/>
<cfloop query="getUsers" >
<cfset resultStuct["data"][count]['id'] = getUsers.id />
<cfset resultStuct["data"][count]['questionone'] = getUsers.questionone />
<cfset resultStuct["data"][count]['questiontwo'] = getUsers.questiontwo />
<cfset Count = Count + 1/>
</cfloop>
<cfreturn SerializeJSON(resultStuct) />
</cffunction>
</cfcomponent>
This discussion has been closed.
Answers
Hi @natfoster ,
You can pass in custom parameters to the Ajax call as in this example,
Cheers,
Colin