Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Send my dynamic checkbox to a function and reference

    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!

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try something like this:

    PHP Code:

    <script type="text/javascript">
    function 
    Activate(chk_statusidea) {
        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.

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank You

    This works great. Sorry for the delayed response... had to get to work to test it out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •