Time:
Scotland: Fri, 10:32 pm Rhode Island: Fri, 5:32 pm Florida: Fri, 5:32 pm New Mexico: Fri, 3:32 pm California: Fri, 2:32 pm
Buy this Ad Space. 180px wide. Please get in touch with KH@ if you are interested and make an offer.
US$10 per year - Save $100s! The Fabulously Unfair WebX Auction Bar. For Ebay etc. Ro-Sham-Bo the opposition. Laugh like Eric Cartman when you win! CLICK HERE NOW!More information and sign-up.
WebXpertz Hosting. Custom fit from $5pm. PHP/MySQL You'll save money, we'll save money. Seems fair to me. Interested? If so Please PM me here and tell me what you need. Thanks!
|
For continued disscussion on this topic : Checkbox Validation
Carol 05-02-2001, 05:27 AM I am wondering if anyone can help me with this problem that i have. Does anyone know how to create 2 checkboxes per record according to the number of records that I have in a database? Only one checkbox can be use at a time, but I cannot use radio button for update purposes...
rt glenn 05-02-2001, 07:19 AM What database are you using? How are you accessing the
database - ASP, PHP, PERL?
If I understand this right, you have one field in a databse that has two possible values. You want to use HTML checkboxes to mimic the radio button feature.
First, you need a form with two checkboxes. When you read that particular database record it's value will be "a" or "b". If the value is "a", the first checkbox will get it's "checked" property set to "1", the second checkbox will get it's "checked" property set to "0". If the value is "b", then vise-versa.
When either of the checkboxes in the form is clicked, you would call a Javascript function to toggle the "checked" property of each box. Then send the results to the database based on which field is checked.
Bob
Carol 05-02-2001, 08:10 AM Hi Bob,
I am currently using Coldfusion language and javascript. I display all the records I have in the database and at the end of each record at each row, it will include two checkboxes (approve, reject). So let's say there are 10 records at the time and the user need to select either he approve or reject for each record and submit the form... I am going insane...Can someone help?!!!
Carol
[Edited by Carol on 05-02-2001 at 02:29 AM]
rt glenn 05-02-2001, 11:09 AM Hi Carol -
The basic process would be the same if you were using ASP, PHP, or ColdFusion. They all connect to the database, read records, and write output. I am familiar with ColdFusion, but definitely not well enough to get a job in it!
Here goes a real, real generic approach - forgive me for lack of ColdFusion tag knowledge. I know it has tags to connect and write HTML output, etc.
<cfm connect to the db>
<cfm read the db>
record=current record from db
<table> cf writing out html
<form method="post" action="update.cfm">
do while (record .ne. EOF)
<tr>
<td>
<input type="text" name="field1">record.field1
</td>
<td>
<input type="text" name="field2">record.field2
</td>
<td>
if (record.approval .eq. "yes")
<input type="checkbox" name="approval" value="yes" checked onchange="javascript:check_boxes()>Approved<br>
<input type="checkbox" name="rejected" value="no" onchange="javascript:check_boxes()> Rejected<br>
else
<input type="checkbox" name="approval" value="yes" onchange="javascript:check_boxes()> Approved<br>
<input type="checkbox" name="rejected" value="no" checked onchange="javascript:check_boxes()> Rejected<br>
end if
</td>
</tr>
end do
<input type="submit" value="Update DB">
</form>
</table>
<cf close db>
For every record you read, your going to create the same html code. Generally in ASP/PHP, you format the data by writing out html form and table tags. When you get to your approval field, you check to see if the status is approved or rejected. In either case, you write out the HTML code for two checkboxes - one <input> tag will specify "checked" and the other one will not. Each <input> tag will also call a javascript function if the box is changed. That script will know which box was changed and change the contents of the other checkbox - just like a radio button. Then the form will be submitted update the db - or I guess you might
have a cf tag for that.
I would suggest asking for help in the ASP/PHP/ColdFusion
forum.
When you have the ColdFusion part figured out, I would be happy to help you with the Javascript :)
Sorry about the ugly code above.
Bob
rtglenn@oongawa.com
Carol 05-03-2001, 02:41 AM Thanx Bob,
you did help. I shall now heed your advice to try out in the coldfusion forum for more advice. Really thanks, thanks, and more thanks... =) And I sure will come back and pester you for more help on javascript, but don't mind me being a nuisance! hee...
rt glenn 05-03-2001, 02:58 AM I'll trade you some Javascript for ColdFusion knowledge! :)
Bob
Carol 05-03-2001, 03:30 AM Bob,
sorry to bother you once again... Can I know what your function javascript:check_boxes() is about?
rt glenn 05-03-2001, 11:42 AM Hi Carol -
I was talking in abstract terms about the "check_boxes()" function. But here is a working example:
<html>
<head>
<title></title>
<script language="Javascript">
function check_approval()
{
if (document.approval.approved[0].checked==1) document.approval.approved[1].checked=0
else document.approval.approved[1].checked=1
populate_field()
}
function check_rejection()
{
if (document.approval.approved[1].checked==1) document.approval.approved[0].checked=0
else document.approval.approved[0].checked=1
populate_field()
}
function populate_field()
{
if (document.approval.approved[0].checked==1) document.record.approved.value="yes"
if (document.approval.approved[1].checked==1) document.record.approved.value="no"
}
</script>
</head>
<body background="images/bback1.jpg" bgcolor="#ffffff" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" id=all>
<form name="record" method="post" action="file.cfm">
<input type="text" name="name" value="J. Doe" size="25"></input>
<br>
<input type="text" name="address" value="123 Main St." size="25"></input>
<br>
<input type="text" name="city" value="Anytown" size="25"></input>
<br>
<input type="text" name="state" value="Anystate" size="25"></input>
<br>
<input type="text" name="zip" value="00000" size="25"></input>
<br>
<input type="text" name="approved" value="" size="25"></input>
<br>
<input type="submit" value="Update Record"></input>
</form>
<form name="approval">
<input type="checkbox" name="approved" value="yes" checked onClick="check_approval()">Approve</input>
<br>
<br>
<input type="checkbox" name="approved" value="no" onClick="check_rejection()">Reject</input>
</form>
</body>
</html>
After each record, you are going to create two check boxes. The check boxes will emulate radio buttons. You can have only on checkbox checked at a time.
The above javascript should be hard coded into your html file. Your coldfusion is going to write out all of the html between the body tags. I would use two forms; the first will just contain placeholder fields for each record you are reading from the db. When you are writing out the html code, just place each field's data in the input tag's value attribute - value="db data". I am assuming you are going to write back the entire record with the addition of another field for approval/rejection. That additional field can be found in the first "record" form.
The second form will be the same for every record - the approval form. It will perform the same function for every record. As it is shown, it will toggle "Approve" and "Reject" fields and write a "yes" or "no" value back to the record form.
When you submit the record form, you'll use the cf to simply update that existing record. I'm not sure if you will need to send the "yes" or "no" approval field back.
The goal is to write the html code from cf just as you would do by hand.
Hopefully I haven't confused you too much. This should at least give you some ideas. I could show you what similar code looks like in ASP or PHP, but I'm not sure if that would help.
If you want to test the above code out, just remove the method= and action= from the first form.
Good luck :)
Bob
Carol 05-04-2001, 07:15 AM Thanks Bob!
rt glenn 05-04-2001, 08:02 AM Hi Carol -
Keep me posted on this as I would love to see what the final ColdFusion-laced code looks like.
Bob
Carol 05-06-2001, 05:46 PM Sure Bob! Promise you I will trade with you for some coldfusion codings right? Hee... =)
jetset 05-16-2001, 08:49 PM just a suggestion/question, if you have 2 states for a record, approved or rejected, why not just have one checkbox
since all records that aren't rejected are aproved?
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.
|