473,386 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Only display checkbox if there is corresponding data

102 100+
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 ?
Jul 25 '07 #1
16 1496
pbmods
5,821 Expert 4TB
Heya, lyealain.

Let's have a look at your code. It may be more practical to do this server-side.
Jul 25 '07 #2
pbmods
5,821 Expert 4TB
Changed thread title to better describe the problem (did you know that threads whose titles contain fewer than three words actually get FEWER responses?).
Jul 25 '07 #3
lyealain
102 100+
Expand|Select|Wrap|Line Numbers
  1. <head>
  2.        <link rel="stylesheet" type="text/css" href="../Styles.css"> 
  3.  
  4. <script type="text/javascript">
  5.  
  6. function validate(form)
  7.         {
  8.             var isChecked = false;
  9.             for(i=0;i<document.frmSend[0].chkSupplier.length;i++)
  10.             {
  11.                 if(document.frmSend[0].chkSupplier[i].checked)
  12.                     isChecked = true;
  13.             }
  14.                 if(!isChecked) alert("Check it!!!");
  15.         }
  16.  
  17. </script>
  18.  
  19. </head> 

Expand|Select|Wrap|Line Numbers
  1. Response.Write("<form name='frmSend' method='post' action='sendSupplier.asp' onsubmit='return validate(this)' >")
  2.  
  3.     Call ReportA()            
  4.  
  5. Response.write("<table width='900'  cellspacing='2' cellpadding='0'><tr><td align='right'><input type=submit name=updAction value='SUBMIT'>&nbsp; </td></tr></table>")
  6.  
  7. Response.Write("</form>")
  8.  
  9. End Function
  10. %>
  11.  
  12. <%
  13. Function ReportA()
  14.  
  15. Response.write("<tr bgcolor='" &color& "'>")
  16. response.write("<td><font class='rec'>" &intRecNo& "</font></td>")
  17.  
  18.     Response.Write("<td><font class='rec'>" &rsReport.Fields("PartNumber")& "</font></td>")    
  19.     Response.Write("<td><font class='rec'>" &rsReport.Fields("PartDesc")& "</font></td>")
  20.     Response.Write("<td><font class='rec'>" &rsReport.Fields("comCode")& "</font></td>")
  21.     Response.Write("<td><font class='rec'>" &rsReport.Fields("MPN")& "</font></td>")
  22.     Response.Write("<td><font class='rec'>" &rsReport.Fields("QMPN")& "</font></td>")
  23.     Response.Write("<td><font class='rec'>" &rsReport.Fields("AML")& "</font></td>")
  24.     Response.Write("<td><font class='rec'>" &rsReport.Fields("SupplierName")& "</font></td>")
  25.     Response.Write("<td><font class='rec'>" &rsReport.Fields("LeadTime")& "</font></td>")
  26.  
  27.  
  28.  
  29.         If CheckAll = "checked" Then
  30.             response.write("<td><input type='checkbox' name='chkSupplier" &count& "' checked value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  31.         Else
  32.             response.write("<td><input type='checkbox' name='chkSupplier" &count& "'  value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  33.         End If
  34.             Response.write("</tr>")
  35. End Function
  36. %>  
i only able to validate if all the checkbox are not checked// then show error..
Jul 25 '07 #4
pbmods
5,821 Expert 4TB
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.,
Expand|Select|Wrap|Line Numbers
  1. if rsReport.Fields("SupplierName") = "" then
  2.     Response.Write("disabled=\"disabled\"/></td>");
  3. else
  4.     Response.Write("/></td>");
  5. end if
  6.  
Jul 25 '07 #5
lyealain
102 100+
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.,
Expand|Select|Wrap|Line Numbers
  1. if rsReport.Fields("SupplierName") = "" then
  2.     Response.Write("disabled=\"disabled\"/></td>");
  3. else
  4.     Response.Write("/></td>");
  5. end if
  6.  

i did this..
Expand|Select|Wrap|Line Numbers
  1. if rsLook.Fields("Supp_Email") = "" then        
  2.  
  3. dim strCBstate 
  4. strCBstate = "disabled"    
  5. else
  6.     strCBstate = ""            
  7. end if 
  8.  
  9. If CheckAll = "checked" Then
  10. response.write("<td><input type='checkbox'  strCBstate name='chkSupplier" &count& "' checked value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  11. Else
  12.  
  13. response.write("<td><input type='checkbox'  strCBstate  name='chkSupplier" &count& "'  value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  14.         End If
but i cant make it disable....
Jul 25 '07 #6
pbmods
5,821 Expert 4TB
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
Jul 25 '07 #7
lyealain
102 100+
thansk.. haha.... pls help on my question.. thanks
Jul 26 '07 #8
pbmods
5,821 Expert 4TB
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?
Expand|Select|Wrap|Line Numbers
  1. response.write("<td><input type='checkbox' " & strCBstate & " name='chkSupplier" ...
  2.  
Jul 26 '07 #9
lyealain
102 100+
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
Jul 26 '07 #10
pbmods
5,821 Expert 4TB
I see.

Why not simply not output the checkbox HTML for the row if the data is invalid?
Jul 26 '07 #11
lyealain
102 100+
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
Jul 27 '07 #12
pbmods
5,821 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" ... />
  2.  
Whereas an invalid checkbox would look like this:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" ... disabled="disabled" />
  2.  
The other option is to make the checkbox invisible:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" ... />
  2. <input type="checkbox" ... style="visibility:hidden;" />
  3.  
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.
Jul 27 '07 #13
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='chkSupplier" &count& "' checked value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
Else

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


</Code>

actually u have to pass the value to 'disabled' attribute
Jul 27 '07 #14
lyealain
102 100+
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...hahahhaaah.

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

Expand|Select|Wrap|Line Numbers
  1. dim strCBstate 
  2.         if rsLook.Fields("Supp_Email") = "" then              
  3.             className= "recHighlight"            
  4.             href = "<b>"
  5.             endhref = "</b>"                
  6.             strCBstate = "disabled"
  7.  
  8.         elseif rsLook.Fields("week1") = ""  then
  9.             className= "pageLink1"
  10.             strCBstate = "disabled"
  11.  
  12.         else
  13.             strCBstate = ""
  14.             className = "pagelink"
  15.             href = ""
  16.             Endhref =""
  17.         end if 
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Function ReportA()
  3.  
  4. Response.write("<tr bgcolor='" &color& "'>")
  5. response.write("<td><font class='rec'>" &intRecNo& "</font></td>")
  6.  
  7.     Response.Write("<td><font class='pageblue'>" &rsReport.Fields("PartNumber")& "</font></td>")    
  8.     Response.Write("<td><font class='rec'>" &rsReport.Fields("PartDesc")& "</font></td>")
  9.     Response.Write("<td><font class='rec'>" &rsReport.Fields("comCode")& "</font></td>")
  10.     Response.Write("<td><font class='rec'>" &rsReport.Fields("MPN")& "</font></td>")
  11.     Response.Write("<td><font class='rec'>" &rsReport.Fields("QMPN")& "</font></td>")
  12.     Response.Write("<td><font class='rec'>" &rsReport.Fields("AML")& "</font></td>")
  13.     Response.Write("<td>"&href&"<a href= '/CLS1/CLSsendmail/Sourcing/CheckSuppEmail.asp?supp="&rsReport.Fields("SupplierName")&"&rfq="&rfq&"&rt="&RequestTime& "&DateNow="&DateNow&"'><font class='"&className&"'><u>" &rsReport.Fields("SupplierName")& "</font></a></u></td>")
  14.     Response.Write("<td><font class='rec'>" &rsReport.Fields("LeadTime")& "</font>"&endhref&"</td>")
  15.  
  16.  
  17.  
  18. If CheckAll = "checked" Then
  19. response.write("<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSupplier" &count& "' checked value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  20.         Else
  21. response.write("<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSupplier" &count& "'  value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
  22.         End If
  23.             Response.write("</tr>")
  24. End Function
  25. %>
in my editor.. it din come out green color.. now all thecheckbox are disabled..!!!!! those with emai... also disabled
Jul 27 '07 #15
pbmods
5,821 Expert 4TB
Heya, lyealain.

Make sure you set strCBState in your loop.

Also, should it be " & strCBState & " instead of " + strCBState + "?
Jul 27 '07 #16
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...hahahhaaah.

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

dim strCBstate
if rsLook.Fields("Supp_Email") = "" then
className= "recHighlight"
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.Fields("PartNumber")& "</font></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("PartDesc")& "</font></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("comCode")& "</font></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("MPN")& "</font></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("QMPN")& "</font></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("AML")& "</font></td>")
Response.Write("<td>"&href&"<a href= '/CLS1/CLSsendmail/Sourcing/CheckSuppEmail.asp?supp="&rsReport.Fields("Supplie rName")&"&rfq="&rfq&"&rt="&RequestTime& "&DateNow="&DateNow&"'><font class='"&className&"'><u>" &rsReport.Fields("SupplierName")& "</font></a></u></td>")
Response.Write("<td><font class='rec'>" &rsReport.Fields("LeadTime")& "</font>"&endhref&"</td>")



If CheckAll = "checked" Then
response.write("<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSupplier" &count& "' checked value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
Else
response.write("<td><input type='checkbox' disabled=""\ + strCBstate + \"" name='chkSupplier" &count& "' value='" &rsReport.Fields("PartNumber")& "/"&rsReport.Fields("PartDesc")& "/" &rsReport.Fields("comCode")& "/" &rsReport.Fields("MPN")& "/" &rsReport.Fields("QMPN")& "/" &rsReport.Fields("AML")& "/" &rsReport.Fields("SupplierName")&"/" &rsReport.Fields("LeadTime")& "'></td>")
End If
Response.write("</tr>")
End Function
%>

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

Hey lyealain,

HAHAHAHAHAAAA,
My code was perfect actually disabled=""\ + strCBstate + \"" is
not a correct practice...b'coz '\' is used to differentiate the nxt character from the actual string flow...

so it should be disabled=\"" + strCBstate + "\" then it won't change the text either to green & would treat it as a string argument while executing:)

& don't forget to set the 'strCBstate' string...u can even try with '&' inplace of '+'

That's it:)
Aug 2 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jack | last post by:
Hi, I have a checkbox the value which goes to a database via a asp page that builds the sql string. In the front end asp page, the checkbox code is written as follows: <i><input...
3
by: Terence Parker | last post by:
I'm not sure whether this question demands a JavaScript answer or a simple HTML one - so apologies for the cross posting. I am grabbing a bunch of data from MySQL using PHP and returning the...
3
by: Scott | last post by:
Relative newbie here, I'm looking to display the value of radio buttons and check boxes on the page before submission. So far I can do most of it. When "Hat" is checked there are to be no color...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: kiran | last post by:
I cratee a form to meet the fallowing requirement. 1. If any node is selected the corresponding checkbox should be checked 2. If any checkbox is clicked the corresponding node should be selected ...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
2
by: Ceema M via DotNetMonster.com | last post by:
Hello all, I have a nested repeater, which displays categories(parent repeater) and corresponding subcategories(child repeater). Both repeaters have checkboxes. When I check category checkbox...
8
by: Jon Weston | last post by:
I'm setting up an Access2003 database with pictures. I put a bound ole picture ctrl on a form that's source is the table that contains the pictures and follow ALL the directions for embedding a...
0
by: remya1000 | last post by:
I have a field called Departments in my database. and I have 3 monitors. So when Page_Load, I need to check number of departments I have in database. And depends upon that number of departments I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.