Link to home
Start Free TrialLog in
Avatar of NASEEMA
NASEEMA

asked on

check box question

hi experts,

<input type="checkbox" default="" name="chk">

<cfquery datasource="test" name="disp">
  select * from employee
</cfquery>


<input type="submit" value="ok" name="submit">

when i check the check box and click on ok button i want to store the name and number into details table.


how to do this.
i tried like this
<cfif chk eq 1>
<cfquery datasource="insert" name="ins">
  insert into details where username =#un# and number=#no#
</cfquery>
</cfif>

Avatar of ndintenfass
ndintenfass

A checkbox will only pass a value if it is checked.  You can either test for the existence of it, or define a default value.

So, if you have a form that looks like:

----------------------------------
<form action="actionPage.cfm" method="post">

<input type="checkbox" name="chk" value="1"> Check Here To Store Name and Number

<br><br>

Name: <input type="text" name="name"><br>
Number: <input type="text" name="number"><br>
<input type="submit" value="ok" name="submit">
</form>
-----------------------------------

On your action page you could do something like:

<cfif isDefined("form.chk") and form.chk is 1>
DO YOUR INSERT
</cfif>

Or,

<cfif structKeyExists(form,"chk") and form.chk is 1>
DO YOUR INSERT
</cfif>

Or,

<cfparam name="form.chk" default="0">
<cfif form.chk is 1>
DO YOUR INSERT
</cfif>



ASKER CERTIFIED SOLUTION
Avatar of anandkp
anandkp
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial