checkbox in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dipti Singh
    New Member
    • Mar 2007
    • 20

    checkbox in javascript

    Hi,

    I have a asp page.in that i hv created some checkboxes as:

    <%for i=1 to c %>
    <tr>
    <td width="27%" align="right" class="TabBodyR alignBrdLess"></td>
    <td class="TabBodyB rdrLess"><input type="text" name="namerecd< %=i%>" size="30%"></td>
    <td class="TabBodyB rdrLess"><input type="text" name="locrecd<% =i%>" size="33%"></td>
    <td class="TabBodyB rdrLess"><input type="checkbox" name="chk<%=i%> " /></td>
    </tr>
    <% next %>

    i have the number of check boxes in hidden text box
    now i want to check these checkboxes using javascript function:

    but i donot know how to refer each check box

    function shiftnames()
    {
    count=document. form1.hidetxt1. value;
    alert(count);
    for (i=1;i<=count;i ++)
    {
    if (document.form1 .chk+i+.checked ==true)
    {
    // some lines
    }
    }
    }

    but the above if statement is not working

    Please help me
    it is very urgent

    Thanks
  • merseyside
    New Member
    • Mar 2007
    • 48

    #2
    Instead of

    Code:
    document.form1.chk+i+.checked==true
    try

    Code:
    document.form1.elements["chk"+i].checked==true
    The former is effectively looking for a form element with name chk+1+ and not chk1.

    Comment

    • Dipti Singh
      New Member
      • Mar 2007
      • 20

      #3
      Thanks a lot for ur suggestion.
      this is working.
      Regards

      Comment

      • surabhi143
        New Member
        • Jun 2007
        • 1

        #4
        checkbox in javascript

        Please Help Me.....
        This is the code i m using in the edit.asp page.....

        <tr><td width="486" valign=top height="1">
        <form method="POST" action="--WEBBOT-SELF--">
        <!--webbot bot="SaveResult s" u-file="fpweb:///_private/form_results.cs v" s-format="TEXT/CSV" s-label-fields="TRUE" --><p>
        <input type="checkbox" name="Chkbox1" value="1"
        <% if sr="True" then %>
        checked="true"
        <% else %>
        unchecked="true "
        <% end if %>
        >RECEIVED
        </form>
        <p>


        </td>
        <td width="486" valign=top height="1">
        <form method="POST" action="--WEBBOT-SELF--">
        <!--webbot bot="SaveResult s" u-file="fpweb:///_private/form_results.cs v" s-format="TEXT/CSV" s-label-fields="TRUE" --><p>
        <input type="checkbox" name="Chkbox2" value="2"
        <% if dr="True" then %>
        checked="true"
        <% else %>
        unchecked="true "
        <% end if %>
        >RECEIVED
        </form>


        now in esave.asp page, following code is used.....

        elseif mode="update" then

        id = Request("frmid" )

        if ((Request.form( "chkbox1") <> "") ) then
        sql = "UPDATE tblGATEPASSn SET SRECD = '1' WHERE GP_ID='" & id & "'"
        else
        sql = " UPDATE tblGATEPASSn SET DRECD = '1' WHERE GP_ID='" & id & "' "
        end if

        oConnection.exe cute sql

        end if


        Here i m not able to update value of DRECD attribute of the table.

        Please suggest the solution for the problem.

        Comment

        Working...