SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Updating multiple records with checkboxes

    Hello,
    I am desperately in need of your help.
    Any suggestion is greatly appreciated

    I have html table populated with data from the database. I also have a checkbox that controls the visibility of a textarea. When this checkbox is checked a textarea will be visible and users can enter a note for each record. At the end of the table I have a button to save all the Modified records .

    I need to capture the primary key of the record being updated

    do while not objRSProject.eof -- getting data from the database

    <tr> <td>objRSProject("id")</td>
    <td>objRSProject("name") etc.....
    <td><input type=checkbox name="chk" onclick="getnext(this)"></td>


    <%if Request.Form("chk") = 'on'

    idid = objRSProject("id")

    -- this gives the wrong primary key. This record's check box is not even checked
    end if
    %>


    <td class="tdHidden"> <textarea rows="1" cols="50" name="Notes"></textarea> </td>
    </tr>

    objRSProject.moveNext
    loop

    end if

    The above table have the primary key that I need to update my table.


    <%If Request.Form("action") = "Update" Then 'This gives me the notes being entered
    response.Write(idid)
    dim a , x
    a = Split(Request.Form("Notes"), ",")
    for each x in a
    ' response.Write(x )
    ' Here I will have my update statement but my problem is getting the primary key of the record that's being edited.
    next
    End If

    %>

  2. #2
    SitePoint Guru
    Join Date
    Jun 2007
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    your posting is a bit confusing . It would help if you clarified the form from the processing code.

    Clicking the checkbox is a client-side action and has nothing to do with activating the server-side ASP code .

    So there will be no value if the checkbox is checked by the user because the ASP code has already run and is no longer active.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I understand about the checkbox onclick being client-side event.
    So how could I identify which records are modified and then update those records.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Location
    Israel
    Posts
    523
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So how could I identify which records are modified and then update those records.
    each checkbox has to have some unique value (i.e some ID from ur database table)
    something like:
    Code:
    <input type="checkbox" name="cb" value="1" />
    <input type="checkbox" name="cb" value="2" />
    and then ur update query should be something like that:
    Code ASP:
    <%
    If Request.Form("action") = "Update" then
    sCB = Request.Form ("cb")
    sSQL = "UPDATE table SET something='something' WHERE IDfield IN (" & sCB & ")"
    end if
    %>

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much. You answered my question.
    Have a great day.


Bookmarks

Posting Permissions

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