View Full Version : Send my dynamic checkbox to a function and reference

04-13-2005, 11:16 PM
I have a table with records in it that have an active/innactive status selector. The selector is a checkbox and all of them are within a form. What I want to have happen is for users to be able to click the checkbox right within the webpage and then depending on the value of that checkbox that is clicked, update the value within the database.

This is what I have - please excuse my lack of knowledge on this stuff - I'm usually working with ASP and SQL - not Javascript and DOM...


function Activate(CurrentBox, Idea) {
alert("Activating Record " + Idea);
alert("De-Activating Record " + Idea);


<input name="cbActive<%=iLoopCounter%>" type="checkbox" onClick="Activate(<%=iLoopCounter%>,<%=strProjectID%>)" value="checkbox" <%if bProjectActive = "T" then%>checked<%end if%>>


The "frmIdeaAdmin.cbActive(CurrentBox).Checked" line above is having problems and I'm also at a loss for how to right the new value to the database. I can probably figure out the database part - but the JavaScript and DOM issues are killing me.

Any help would be totally cool!


04-14-2005, 01:13 AM
Try something like this:

<script type="text/javascript">
function Activate(chk_status, idea) {
alert("Activating Record " + idea);
alert("De-Activating Record " + idea);
var db=new Image();

<input name="cbActive<%=iLoopCounter%>" type="checkbox" onclick="Activate(this.checked,<%=strProjectID%>)" value="checkbox" <%if bProjectActive = "T" then%>checked="checked"<%end if%> />

In the onclick event handler we use the keyword this and the property checked to pass true or false into the function what gets passed will depend on the state of the checkbox after the click occurs.

In the function we alert based on the true/false status of the checkbox.

We then set up a variable to hold an image and make a call to the image. In reality we are not going to do anything with an image we are just doing it so we can interact with the server without leaving the page. Notice that the src of the image is actually an asp page that you will set up to handle getting the data out of the query string and interacting with your DB.

04-14-2005, 05:30 PM
This works great. Sorry for the delayed response... had to get to work to test it out.