Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help in JScript and ASP

Status
Not open for further replies.

Akaramat

Programmer
Jul 11, 2001
1
US
Hello everyone !
I am a novice in ASP and HTML realm and need some serious help. I am trying to develop a ASP document that would pull some data from a Database (In Access 2000) and then display them on a table. Now that much I have fiqures ... no problem there. My tabel is of three colums. The first colum is a CheckBox, the second and third is the data from the DB. The heading for the CheckBox colum also has a Checkbox. What I want to do is select all the checkboxes (Meaning CHKECH THEM ALL) when the checkbox in the heading is checked. So I want to do somthing like a basic Hotmail Inbox thing when the top checkbox is pressed all the checkboxes in the table are checked also. Now here is what I have so far


<%
'This is the heading
<TR><TD> <input type=checkbox name=ALL value= onClick=SetChecked(4);> </TD> <TH width=738> <font size=2> <u>Message</u></font> </TH> <TH width=120> <font size=2 > <u>Date</u></font> </TH> </TR>&quot;


'Filling the Table with Data
Do While NOT rsdata.EOF
'i is just to see how many rows I get. Here RSDATA is my recordset in the database
i = i + 1
Response.Write &quot;<TR><TD><input type=checkbox name=m&quot; & i & &quot; </TD>&quot; & &quot;<TD >&quot; & rsdata(&quot;Message&quot;) & &quot;</TD>&quot; & &quot;<TD align=center>&quot; & rsdata(&quot;Date&quot;) & &quot;</TD>&quot; & &quot;</TR>&quot;
rsdata.MoveNext
Loop
%>

Now here is the Function that I wrote for the ONCLICK event for the Checkbox in the Heading


<script language=&quot;JavaScript&quot;>
<!--
function SetChecked(val)
{
dml= document.MainTable;
len = 4;
for( i=1 ; i<len ; i++)
{
//Here is the problem.... How do I refer to my Chekcboxes
// This will work m1.checked= true; or m2.checked= true;
// But I want to be able to go through the loop and turn them on.
// I think I am just goofing off on the syntax.
mi.checked= true;
}
}

// -->

</SCRIPT>

//////////////////


Check out my comments with the Function to see what i mean .. I need help bacially on the syntax in Jscript Can any one help please !!!!
Thanks
Adil
 
Set up a counter in ASP that increments every time a record is written. Then after the loop is done, assign that number to a hidden form variable. Then in your jscript, get that number and use it for the upper bound of the loop.

so, in the ASP, do this after you close the loop:

Code:
<input type=&quot;hidden&quot; name=&quot;counter&quot; value=&quot;<%= counter%>&quot;>

then inside your function do this:

Code:
len = document.forms[0].counter.value;

Hope that helps some... the only way I know of to make the ASP pass variables to the JS is via form data...

-Scott





 
Hi Scott,

you can easily pass variables from ASP, VBScript to JS like so:

<html>
<body>
<%
variable = &quot;whatever&quot;
response.write(&quot;<script type='text/javascript'>jsvar='&quot; & variable & &quot;';</script>&quot;)
%>
<script type=&quot;text/javascript&quot;>
document.write(jsvar);
</script>
</body>
</html>

Bye.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top