Only display checkbox if there is corresponding data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lyealain
    New Member
    • May 2007
    • 102

    Only display checkbox if there is corresponding data

    let say i use for loop to display the record from database/// and each line of records has a checkbox ..

    in a row.. if let say one of the column does not fulfill the requriement !! don allow it to check the checkbox...

    e.g. if let say rsLook.Fields(" Supp_Email") = "" then
    don allow it to check

    how can i do that ?
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, lyealain.

    Let's have a look at your code. It may be more practical to do this server-side.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Changed thread title to better describe the problem (did you know that threads whose titles contain fewer than three words actually get FEWER responses?).

      Comment

      • lyealain
        New Member
        • May 2007
        • 102

        #4
        [code=javascript]<head>
        <link rel="stylesheet " type="text/css" href="../Styles.css">

        <script type="text/javascript">

        function validate(form)
        {
        var isChecked = false;
        for(i=0;i<docum ent.frmSend[0].chkSupplier.le ngth;i++)
        {
        if(document.frm Send[0].chkSupplier[i].checked)
        isChecked = true;
        }
        if(!isChecked) alert("Check it!!!");
        }

        </script>

        </head> [/code]


        [code=asp]Response.Write( "<form name='frmSend' method='post' action='sendSup plier.asp' onsubmit='retur n validate(this)' >")

        Call ReportA()

        Response.write( "<table width='900' cellspacing='2' cellpadding='0' ><tr><td align='right'>< input type=submit name=updAction value='SUBMIT'> &nbsp; </td></tr></table>")

        Response.Write( "</form>")

        End Function
        %>

        <%
        Function ReportA()

        Response.write( "<tr bgcolor='" &color& "'>")
        response.write( "<td><font class='rec'>" &intRecNo& "</font></td>")

        Response.Write( "<td><font class='rec'>" &rsReport.Field s("PartNumber") & "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("PartDesc") & "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("comCode")& "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("MPN")& "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("QMPN")& "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("AML")& "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("SupplierName ")& "</font></td>")
        Response.Write( "<td><font class='rec'>" &rsReport.Field s("LeadTime") & "</font></td>")



        If CheckAll = "checked" Then
        response.write( "<td><input type='checkbox' name='chkSuppli er" &count& "' checked value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
        Else
        response.write( "<td><input type='checkbox' name='chkSuppli er" &count& "' value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
        End If
        Response.write( "</tr>")
        End Function
        %> [/code]

        i only able to validate if all the checkbox are not checked// then show error..

        Comment

        • pbmods
          Recognized Expert Expert
          • Apr 2007
          • 5821

          #5
          Heya, lyealain.

          Here's how I would handle that situation. Instead of using JavaScript, have your ASP code check the value of the field, and if it is empty, set the disabled property of the checkbox.

          E.g.,
          [code=asp]
          if rsReport.Fields ("SupplierName" ) = "" then
          Response.Write( "disabled=\"dis abled\"/></td>");
          else
          Response.Write( "/></td>");
          end if
          [/code]

          Comment

          • lyealain
            New Member
            • May 2007
            • 102

            #6
            Originally posted by pbmods
            Heya, lyealain.

            Here's how I would handle that situation. Instead of using JavaScript, have your ASP code check the value of the field, and if it is empty, set the disabled property of the checkbox.

            E.g.,
            [code=asp]
            if rsReport.Fields ("SupplierName" ) = "" then
            Response.Write( "disabled=\"dis abled\"/></td>");
            else
            Response.Write( "/></td>");
            end if
            [/code]

            i did this..
            [code=asp]if rsLook.Fields(" Supp_Email") = "" then

            dim strCBstate
            strCBstate = "disabled"
            else
            strCBstate = ""
            end if

            If CheckAll = "checked" Then
            response.write( "<td><input type='checkbox' strCBstate name='chkSuppli er" &count& "' checked value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
            Else

            response.write( "<td><input type='checkbox' strCBstate name='chkSuppli er" &count& "' value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
            End If[/code]

            but i cant make it disable....

            Comment

            • pbmods
              Recognized Expert Expert
              • Apr 2007
              • 5821

              #7
              Heya, lyealain.

              Thanks for using CODE tags! Did you know that you can specify a language for your CODE tags to make your source code easier to read?

              You will still need to use [/CODE] to close your code blocks, regardless of the language, but you can the use one of these tags to open your code block:

              [CODE=html]
              [CODE=javascript]
              [CODE=asp]

              and so on.

              Thanks!

              MODERATOR

              Comment

              • lyealain
                New Member
                • May 2007
                • 102

                #8
                thansk.. haha.... pls help on my question.. thanks

                Comment

                • pbmods
                  Recognized Expert Expert
                  • Apr 2007
                  • 5821

                  #9
                  What's the HTML output looking like? I'm not really familiar with ASP, but it looks as though your code outputs the literal 'strCBstate' instead of the value of strCBstate.

                  Did you mean this instead?
                  [code=asp]
                  response.write( "<td><input type='checkbox' " & strCBstate & " name='chkSuppli er" ...
                  [/code]

                  Comment

                  • lyealain
                    New Member
                    • May 2007
                    • 102

                    #10
                    wat i wan is actually ... imagine that we display 10 rows from database...
                    each row has checkbox...

                    so .. i wan the system automatic hide the checkbox at the (e.g) third row if the column at third row does not fulfill the requirement

                    Comment

                    • pbmods
                      Recognized Expert Expert
                      • Apr 2007
                      • 5821

                      #11
                      I see.

                      Why not simply not output the checkbox HTML for the row if the data is invalid?

                      Comment

                      • lyealain
                        New Member
                        • May 2007
                        • 102

                        #12
                        Originally posted by pbmods
                        I see.

                        Why not simply not output the checkbox HTML for the row if the data is invalid?
                        can but it look ugly... hahahaha... how do i make that disabled... ? thanks experrt

                        Comment

                        • pbmods
                          Recognized Expert Expert
                          • Apr 2007
                          • 5821

                          #13
                          Fair enough.

                          Ok. So you've got your table cell. Now you need to be able to hide or disable the checkbox if the data is invalid.

                          Here are some ideas.

                          The first idea is to disable it.
                          A valid checkbox would look like this:
                          [code=html]
                          <input type="checkbox" ... />
                          [/code]

                          Whereas an invalid checkbox would look like this:
                          Code:
                          <input type="checkbox" ... disabled="disabled" />
                          The other option is to make the checkbox invisible:
                          [code=html]
                          <input type="checkbox" ... />
                          <input type="checkbox" ... style="visibili ty:hidden;" />
                          [/code]

                          The latter will still take up space as if the checkbox were there, but it will be invisible and will not respond to clicks.

                          You have the right idea in your ASP code; if the checkbox is invalid, you output some extra attribute that makes the checkbox disabled. You just have to figure out what it is that your code is doing that it is not supposed to be doing.

                          Comment

                          • nagarwal
                            New Member
                            • Jun 2007
                            • 13

                            #14
                            Hi ,

                            Try this thing..

                            < Code: ( asp )>
                            if rsLook.Fields(" Supp_Email") = "" then

                            dim strCBstate
                            strCBstate = "disabled"
                            else
                            strCBstate = ""
                            end if

                            If CheckAll = "checked" Then
                            response.write( "<td><input type='checkbox' disabled=\"" + strCBstate + "\" name='chkSuppli er" &count& "' checked value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
                            Else

                            response.write( "<td><input type='checkbox' disabled=\"" + strCBstate + "\" name='chkSuppli er" &count& "' value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
                            End If


                            </Code>

                            actually u have to pass the value to 'disabled' attribute

                            Comment

                            • lyealain
                              New Member
                              • May 2007
                              • 102

                              #15
                              thanks for reply... i think the bold one should be written like this
                              disabled=""\ + strCBstate + \"" ????

                              BUT now it disabled everything... even those with the email exist...hahahha aah.

                              if put disabled=""\ + strCBstate + "\" got error
                              here is my complete code..!!!

                              [CODE=asp]dim strCBstate
                              if rsLook.Fields(" Supp_Email") = "" then
                              className= "recHighlig ht"
                              href = "<b>"
                              endhref = "</b>"
                              strCBstate = "disabled"

                              elseif rsLook.Fields(" week1") = "" then
                              className= "pageLink1"
                              strCBstate = "disabled"

                              else
                              strCBstate = ""
                              className = "pagelink"
                              href = ""
                              Endhref =""
                              end if [/CODE]

                              [CODE=asp]
                              <%
                              Function ReportA()

                              Response.write( "<tr bgcolor='" &color& "'>")
                              response.write( "<td><font class='rec'>" &intRecNo& "</font></td>")

                              Response.Write( "<td><font class='pageblue '>" &rsReport.Field s("PartNumber") & "</font></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("PartDesc") & "</font></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("comCode")& "</font></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("MPN")& "</font></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("QMPN")& "</font></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("AML")& "</font></td>")
                              Response.Write( "<td>"&href &"<a href= '/CLS1/CLSsendmail/Sourcing/CheckSuppEmail. asp?supp="&rsRe port.Fields("Su pplierName")&"& rfq="&rfq&"&rt= "&RequestTi me& "&DateNow="&Dat eNow&"'><font class='"&classN ame&"'><u>" &rsReport.Field s("SupplierName ")& "</font></a></u></td>")
                              Response.Write( "<td><font class='rec'>" &rsReport.Field s("LeadTime") & "</font>"&endhref& "</td>")



                              If CheckAll = "checked" Then
                              response.write( "<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSuppli er" &count& "' checked value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
                              Else
                              response.write( "<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSuppli er" &count& "' value='" &rsReport.Field s("PartNumber") & "/"&rsReport.Fiel ds("PartDesc") & "/" &rsReport.Field s("comCode")& "/" &rsReport.Field s("MPN")& "/" &rsReport.Field s("QMPN")& "/" &rsReport.Field s("AML")& "/" &rsReport.Field s("SupplierName ")&"/" &rsReport.Field s("LeadTime") & "'></td>")
                              End If
                              Response.write( "</tr>")
                              End Function
                              %>[/CODE]

                              in my editor.. it din come out green color.. now all thecheckbox are disabled..!!!!! those with emai... also disabled

                              Comment

                              Working...