Results 1 to 11 of 11
  1. #1
    Join Date
    Dec 2008
    Posts
    36

    Unanswered: In clcik of button select all checkboxes and direct to another page

    Hi all
    I have a asp page in which i am displaying values from database using html table
    on click of button all checkboes should be selected and page is directed to another page

    <table>
    <tr>
    <td>
    <input type="checkbox" name="some_name" value=<%=rs1("Container_No").Value%>
    </td>
    <td>
    <%=rs1("Container_No").Value%>
    </td>
    <td>
    <%=rs1("Seal_No").value%>
    </td>
    <td><%=rs1("Origin")%></td>
    <td><%=rs1("Arrival_Time")%></td>
    </tr>
    </table>


    Thanks and regards
    Ravi

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Does the button submit the form?
    George
    Home | Blog

  3. #3
    Join Date
    Dec 2008
    Posts
    36
    Hi
    No button does submit the form
    on click of button all check boxes should be selected and directed to another page

    Thanks
    RAvi

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by ravisakee
    and directed to another page
    i.e. submitted?
    George
    Home | Blog

  5. #5
    Join Date
    Dec 2008
    Posts
    36
    Hi
    On click it will directed to another page
    but i am not using any values from the previous page
    just i want to select all checkboxes and direct to another page


    Thanks
    Ravi

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You can do the checking on client side using JavaScript or...
    Code:
    <html>
    <head>
    	<title>Checkbox Checking Check Checker</title>
    </head>
    <body>
    
    	<%
    	Dim selected
    	If Request.Querystring("checked") = "true" Then
    		checked = "checked='checked'"
    	Else
    		checked = ""
    	End If
    	%>
    
    	<form id="main_form" action="do_something.asp" method="post">
    		<%
    		Dim i
    		For i = 0 To 10
    		%>
    
    		<input type='checkbox' name='some_name' value='<%=i%>' <%=checked%> />
    
    		<%
    		Next
    		%>
    	</form>
    
    	<form id="checker" action="this_page.asp" method="get">
            <%
    		If checked = "" Then
            %>
    			<input type='hidden' name='checked' value='true' />
    			<input type='submit' value='Check all' />
            <%
    		Else
            %>
    			<input type='hidden' name='checked' value='false' />
    			<input type='submit' value='Uncheck all' />
            <%
    		End If
            %>
    	</form>
    
    </body>
    </html>
    George
    Home | Blog

  7. #7
    Join Date
    Dec 2008
    Posts
    36
    hi
    how to do it on clent side??
    if i have multiple checkboxes i will loop through and check
    here i have only one checkbox which will dynamically generate many
    how to select all???

    Thats my question

    Thanks
    RAvi

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The method posted above does it server side. This is a good method because not all people will have JavaScript enabled.

    Here's an example in JavaScript
    Code:
    <html>
    <head>
        <title>Checkbox Checking Check Checker</title>
        <script language="JavaScript">
    	    function checkThem(check) {
    		    for (i=0; i<document.main_form.some_name.length; i++) {
    			    document.main_form.some_name[i].checked = check;
    		    }
    	    }
        </script>
    </head>
    <body>
    
        <form name="main_form" action="do_something.asp" method="post">
    	    <%
    	    Dim i
    	    For i = 0 To 10
    	    %>
    
    	    <input type='checkbox' name='some_name' value='<%=i%>' <%=checked%> />
    
    	    <%
    	    Next
    	    %>
    
            <input type='button' name='CheckAll' value='Check All' onClick='checkThem(true)' />
            <input type='button' name='UncheckAll' value='Uncheck all' onClick='checkThem(false)' />
        </form>
    
    </body>
    </html>
    George
    Home | Blog

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Different spin on the same js method
    Code:
    <html>
    <head>
        <title>Checkbox Checking Check Checker</title>
        <script language="JavaScript">
            function checkUnCheck() {
                var check;
                if (document.main_form.reCheck.value == "Check All") {
                    check = true;
                    document.main_form.reCheck.value = "Uncheck All";
                }
                else {
                    check = false;
                    document.main_form.reCheck.value = "Check All";
                }
    
    		    for (i=0; i<document.main_form.some_name.length; i++) {
    			    document.main_form.some_name[i].checked = check;
    		    }
            }
        </script>
    </head>
    <body>
    
        <form name="main_form" action="do_something.asp" method="post">
    	    <%
    	    Dim i
    	    For i = 0 To 10
    	    %>
    
    	    <input type='checkbox' name='some_name' value='<%=i%>' <%=checked%> />
    
    	    <%
    	    Next
    	    %>
    
            <input type='button' name='reCheck' value='Check All' onClick='checkUnCheck()' />
        </form>
    
    </body>
    </html>
    George
    Home | Blog

  10. #10
    Join Date
    Dec 2008
    Posts
    36
    Hey can i have two events on one button click???

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You can have a function that calls a function...
    George
    Home | Blog

Posting Permissions

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