...

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



pixrite
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) {
if{frmIdeaAdmin.cbActive(CurrentBox).Checked){
alert("Activating Record " + Idea);
}
if{!frmIdeaAdmin.cbActive(CurrentBox).Checked){
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!

Thanks!

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




<script type="text/javascript">
function Activate(chk_status, idea) {
if(chk_status){
alert("Activating Record " + idea);
}else{
alert("De-Activating Record " + idea);
}
var db=new Image();
db.src="somepage.asp?status="+chk_status+"&rec="+idea;
}
</script>


<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.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum