[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Re-populate Radio Buttons and Check Boxes

Posted on 2005-05-09
Medium Priority
Last Modified: 2011-10-03
Hi Experts,
I use a web form to allow our customers to post Job Orders on our website. The web form uses text boxes, check boxes and radio buttons. I am going to write a CGI script that will allow users to go back and edit their existing Job Orders on the website.

My question is: I know how to re-populate the Text Boxes, but when it comes to Radio Buttons and Check Boxes, that is a whole new animal to me. Once I grab the values from my mySQL database, how do I re-populate the values for the Check Boxes and Radio Buttons? I have never tried to do this before.

Thanks everyone in advance for all of your help,

Question by:jahmekyat

Expert Comment

ID: 13960425
Both elements, checkboxes and radios, have an additional html attribute: checked
So you have to compare for every checkbox and every radio button wether that elements value was checked before and set the "checked" attribute if it was.
LVL 25

Accepted Solution

archrajan earned 2000 total points
ID: 13960482
see this example based on some hidden fields u populate radio and checkboxes

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<TITLE> New Document </TITLE>


<form name = "frm">
<input type = "hidden" name = "rad" value = "yes">
<input type = "hidden" name = "chk" value = "true">

<input type = "radio" name = "radio1" value = "yes">yes

<input type = "radio" name = "radio1" value = "no">no

<input type = "checkbox" name = "chk1" >

for(i=0; i <document.frm.radio1.length;i++)
if(document.frm.radio1[i].value == document.frm.rad.value)
document.frm.radio1[i].checked = true;

if(document.frm.chk.value == "true")
document.frm.chk1.checked = true;

LVL 17

Expert Comment

by:Cem Türk
ID: 15697327
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I will leave the following recommendation for this question in the Cleanup topic area:
    Split between NETTY4 and archrajan

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

EE Cleanup Volunteer

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

872 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