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 8 of 8
  1. #1
    New Coder
    Join Date
    Jun 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Checkbox Values

    I have a form that I use to put servers in what we call maintenance mode. It's just a (dynamic) list of servers that the user will toggle a checkbox to put the respective server in maintenance mode. I'm using the objid (serverid) as the checkbox value, checking for null, and if not, then set the maintenance mode. However, I'm not passing anything at all. Below is my form and ASP code:

    Form Code:
    Code:
    <form action="updatemm_select.asp" method="get">
    <table >
            <td><input name="toggle_maint" type="checkbox" value="<% = objid %>">
            </td>
        </tr>
            <%rsqdb.MoveNext%>
            <%loop%>
    <tr>
      <td align=center colspan=6>
      <input type="submit" value="Toggle Maint Mode" name="Maint">
      </td>
    </tr>
    </table>

    ASP Code (updatemm_select.asp)
    Code:
    <%
    Dim serverid, conn, rsUpdate, machineid, status, rsqdbmmon, rsqdbmmoff, strquery, rs, toggle_maint, command, maint
    
    Function ChkString(string)
    If string = "" Then string = " "
    ChkString = Replace(string, "'", "'")
    End Function
    
    serverid = ChkString(Request.QueryString("serverid"))
    machineid = ChkString(Request.QueryString("machineid"))
    toggle_maint = ChkString(Request.QueryString("toggle_maint"))
    maint = ChkString(Request.Form("maint"))
    
    
    set Conn=Server.CreateObject("ADODB.Connection")
    set rs = server.CreateObject("ADODB.Recordset")
    Conn.open "Provider=sqloledb;Server=server;Initial Catalog=db;UID=user;PWD=pw;"
    
    strQuery = "select name, status, objid from object where (objid like '" & Request.QueryString("objid") & "%') "
    
    Set RS = conn.Execute( strQuery)
    
    if request.querystring("objid") <> "" then
    response.write ("ObjID: " )
    response.write rs("objid")
    end if

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Ummmm...
    Code:
    Function ChkString(string) 
        If string = "" Then string = " " 
        ChkString = Replace(string, "'", "'") 
    End Function
    The line in red is totally bogus. Kill it before it multiplies. The *LAST* thing you want to do is convert "" to a space!

    As for the rest...

    Code:
    strQuery = "select name, status, objid from object where (objid like '" & Request.QueryString("objid") & "%') "
    Where, pray tell, in your <form> to you see a field named objid???

    The only field you show is this one:
    Code:
    <input name="toggle_maint" type="checkbox" value="<% = objid %>">
    Secondly, given that toggle_maint contains exactly and precisely the value objid why would you then use LIKE in your query?

    Thirdly, if the objid field in the DB is a NUMBER, then you should never put apostrophes around the value in the query.

    Fourthly, what do you do if the user checks 2 or 3 or 4 of those checkboxes?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New Coder
    Join Date
    Jun 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your input Old Pedant. Let me start over. Here's the form data I'm trying to capture. I have a list of servers that I want to either put into or take out of maintenance mode, based on their checkbox selection. (See image)

    I'm not sure how to capture the serverid when the form is submitted. I thought I could use the serverid as the value object but no luck.
    Attached Thumbnails Attached Thumbnails Passing Checkbox Values-capture.jpg  

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    I would rather have seen the HTML instead of the screen shot.

    You do that by bringing up the page in your browser, clicking on the VIEW menu of the browser, then the SOURCE or PAGE SOURCE menu item. That shows you the HTML as the browser sees it. Copy/paste the relevant code from that.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Jun 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That screenshot was a mockup because I was posting from home and didn't have access to my code. Here's my code:

    Code:
    <form action="updatemm_select.asp" method="get">
    <table >
            <td><input name="toggle_maint" type="checkbox" value="<% = objid %>">
            </td>
        </tr>
            <%rsqdb.MoveNext%>
            <%loop%>
    <tr>
      <td align=center colspan=6>
      <input type="submit" value="Toggle Maint Mode" name="Maint">
      </td>
    </tr>
    </table>

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Please go read what I wrote, again.

    First of all, I *KNOW* that is *NOT* really your code.

    You don't have the beginning of the loop shown, you don't show where objid comes from (probably from objid = rsqdb("some field name" but you don't show that).

    And the HTML isn't even legal HTML. (A missing <tr> if nothing else.)

    But that isn't why I wanted to see the HTML AND NOT THE ASP code. I wanted to see the KINDS of values that will be *IN* those checkbox values. Yes, it's important.
    Last edited by Old Pedant; 11-07-2012 at 01:04 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Oh, and you never mentioned: Is there any reason a user couldn't check ANY NUMBER of the checkboxes before submitting the <form>?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Also, is there some reason you are using method="get" in your <form> tag instead of method="post"?

    And is this page private to your company? That is, is the page accessible on the internet or is it strictly an inTRAnet page? If it is on the inTERnet, is it password protected?

    FWIW, *IF* all my suspicions are correct, I *THINK* you will be able to simply do this on your updatemm_select.asp page to make it change *ALL* of the checked items to maintenance mode:
    Code:
    <%
    set Conn=Server.CreateObject("ADODB.Connection")
    Conn.open "Provider=sqloledb;Server=server;Initial Catalog=db;UID=user;PWD=pw;" 
    
    sql = "UPDATE object SET status = 'maintenance' WHERE objid IN (" & Request("toggle_maint") & ")"
    howmany = 0
    conn.Execute sql, howmany
    
    Response.Write "Changed " & howmany & " to maintenance mode"
    conn.Close
    %>
    (The actual value you set status to of course depends on your needs, but that's the general idea.)

    If you want, you can just try that code to see if it works.

    But if it doesn't work, then I need all that I have asked for from you.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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