Web Analytics Made Easy -
StatCounter choose check boxes in order from bottom - CodingForum

Announcement

Collapse
No announcement yet.

choose check boxes in order from bottom

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • choose check boxes in order from bottom

    Hi,


    For a search criteria ie depending upon the value in combo box,when a hyperlink search is clicked ,records which match this criteria will be displayed to the user.


    there will be a check box against each record,for example like hotmail site or yahoo.the user can choose records and delete them.


    But one restiction i have to impose is that,the user can choose records only from bottom and in order.ie If there are 10 records displayed,he can choose 10th,9th,8th in order.


    he cannot choose 10th ,then 4 and the 7th like that.He has to choose records in order from the bottom and the delete.If he chooses wrongly i have to give a alert saying choose records in order from bottom.


    How can i validate using javascript.Thanks in advance.

    Rama

  • #2
    i think this one is gonna get complicated. my first thought, is that you must have all of the records, except for #10, disabled. then, if the user clicks on #10, #9 will become enabled. you'd have to also have a function set up, to check if the user then unchecks #10, though.

    what i'm thinking, is that you'll need 3 functions. you'll need a generic function that will run at OnClick, and check to see if the Checkbox is checked, or unchecked. then, it will run one function if the checkbox is checked, and another if the checkbox is unchecked.

    the function for being checked would be fairly simple. it would only have to enable the checkbox before it.

    the function for being unchecked, though, would need to be a bit more complicated. it would need to first uncheck all check boxes before it, and then disable them again.
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

    Comment


    • #3
      validate check box

      Hi,

      Can u just give me the code for validating the check boxes.It will be very useful to me.


      Thanks
      Rama

      Comment


      • #4
        choose check boxes in order

        Hi,

        Can anybody help me with the code for validating the check boxes for the above mentioned senario.It will be very useful to me.


        Thanks
        Rama

        Comment


        • #5
          Think this works:
          Code:
          <html>
          <head>
          <title>untitled</title>
          <script type="text/javascript" language="JavaScript">
          
          function in_order(box) {
          var msg = 'Please delete these records in ascending order only, starting from the last.';
          var el, prevEl, nextEl, e = -1, f = box.form;
          while (el = f.elements[++e]) if (el == box) {
          prevEl = (f.elements[e-1]) ? f.elements[e-1] : null;
          nextEl = (f.elements[e+1]) ? f.elements[e+1] : null;
          break;
          }
          if ((prevEl && prevEl.type == 'checkbox' && prevEl.checked) || 
          (nextEl && nextEl.type == 'checkbox' && !nextEl.checked)) {
          alert(msg);
          return false;
          }
          return true;
          }
          
          </script>
          </head>
          <body>
          <form>
          <table border="1" bgcolor="salmon">
          <tr><td colspan="2"><input type="text" size="10" value="Bottoms Up!"></td></tr>
          <tr><td>delete</td><td>record</td></tr>
          <tr><td align="center"><input type="checkbox" value="box1" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>1</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box2" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>2</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box3" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>3</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box4" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>4</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box5" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>5</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box6" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>6</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box7" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>7</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box8" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>8</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box9" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>9</strong></td></tr>
          <tr><td align="center"><input type="checkbox" value="box10" 
          onclick="return in_order(this)"></td>
          <td align="center"><strong>10</strong></td></tr>
          <tr><td colspan="2" bgcolor="coral"><input type="text" size="10"></td></tr>
          <tr><td colspan="2" bgcolor="coral"><input type="text" size="10"></td></tr>
          </table>
          </form>
          </body>
          </html>
          Last edited by adios; Jul 3, 2002, 02:29 PM.

          Comment


          • #6
            Here is some code I wrote that is very very similar to what you need. Mine is more of a brute-force method, but I didn'thave that many checkboxes to handle. Basically it enforces these rules: *something* must be checked. If the "none of the above" check box is checked, none of the others may be checked. If any/all/some of the choices are checked, then the "none of the above" cannot be checked.


            Code:
            <script language="javascript">
            
            function ClearTypeNone() {
               document.DBForm.fTypeNone.checked = false;
            
            // Make sure *something* is checked - it's a required field	
            	if (document.DBForm.fTypeCase.checked == false    &&
                  document.DBForm.fTypeFacility.checked == false &&
                  document.DBForm.fTypeProvider.checked == false &&
                  document.DBForm.fTypeAddress.checked == false) {
            		
            	   document.DBForm.fTypeNone.checked = true
            	}
            }  // end ClearTypeNone
            
            
            function ClearAllTypes() {
               if (document.DBForm.fTypeNone.checked) {
            	
                  document.DBForm.fTypeCase.checked = false;
                  document.DBForm.fTypeFacility.checked = false;
                  document.DBForm.fTypeProvider.checked = false;
                  document.DBForm.fTypeAddress.checked = false
               }
            // Make sure *something* is checked - it's a required field	
            	if (document.DBForm.fTypeCase.checked == false    &&
                  document.DBForm.fTypeFacility.checked == false &&
                  document.DBForm.fTypeProvider.checked == false &&
                  document.DBForm.fTypeAddress.checked == false) {
            		
            	   document.DBForm.fTypeNone.checked = true
            	}
            }  // end ClearAllTypes

            Now here's the checkbox objects

            Code:
                  <input type="checkbox" name=fTypeCase value = "Y" onclick=ClearTypeNone()>Case 
                  <input type="checkbox" name=fTypeFacility value = "Y" onclick=ClearTypeNone()>Facility
                  <input type="checkbox" name=fTypeProvider value = "Y" onclick=ClearTypeNone()>Provider
                  <input type="checkbox" name=fTypeAddress value = "Y" onclick=ClearTypeNone()>Address
                  <input type="checkbox" name=fTypeNone value = "Y" CHECKED onclick=ClearAllTypes()>Not Available
            Last edited by RadarBob; Jul 2, 2002, 07:08 PM.

            Comment


            • #7
              checkboxes in order

              Hi,

              It works fine.Thank u for the help.


              Rama

              Comment

              Working...
              X