Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2006, 05:44 AM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I find out which checkbox has been ticked?

I have created an ASP page which outputs data from a database displaying contents of a basket. This all works fine. One of the fields that is displayed is the 'quote basket name' which I have displayed in an input text field to allow a user to edit it. Next to each record that is displayed I have put a tickbox that the user must select meaning they want to edit just that record, they then edit the basket name text input field right next to the checkbox. I can return the 'value' of the check box selected which returns the basket id - this works. I have created an array to hold all the text input field values. I now need some way of getting the index or order of the checkbox selected and then linking it to the appropriate index in the array so as to know this is the correct basket name to update. I am having a problem finding out how to get the 'order' or index of the checkbox selected.


I have no problem returning the basket id (which is the 'value' of the checkbox ticked). No problems at all with the basket itself). My only problem is updating the database with the basket name (this is an 'editable' field in the display grid) based on what the user has entered in the field AND which checkbox has been ticked. Each check box holds the basket id (as its value). This I can return no problem - the question is I can't 'link' up the checkbox in any way to the basket name text input field.

Ideally I would want to get the 'ID' or order of the checkbox that was ticked. And then use this index to return the associated index in the array (the array holds all the basket name input field values).

For example if I have 5 records being displayed. The user ticks the third checkbox down. I need a way of knowing that this is the THIRD checkbox. Then with the 'number 3' I can use this to return the item in the array with an index of 2 (as an array always starts at 0, so this would in effect therefore be the third basket name item in the array - and therefore the basket name 'linked' with the third checkbox that was ticked). My problem is I have no idea how to work out that it was the third checkbox ticked.

Is there any way to do this?

How would an onBlur example work?

Thank you again for any help.


Please can someone help me with this problem. Thank you very much for any help.



Here is the code that should be run when a user clicks an update 'button' (the input text field and checkbox field is at the bottom of the code):


'-------------------------------
'get the basket name that user has entered and put into array

formbasketname = Request.Form("sel_quotename")
formarray = Split(formbasketname,", ")
for j=0 to Ubound(formarray)
Response.Write "<br>" & formarray(j) 'TEST display contents of array - (this all works)
next 'move to next element in array


Set rsBasket = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM tvQuoteBasket_GetBasket WHERE user_id = " & userid
rsBasket.Open strSQL, cnnConn, 1, 4
rsBasket.MoveFirst

do

'get the checkbox value selected by the user - this holds the basketid value - (this works)
chkboxvalue = Request.Form("chkbox")(i)


'******NOW NEED TO GET THE BASKET NAME ENTERED BY USER THAT IS ASSOCIATED WITH THE CHECKBOX SELECTED
'******THEREFORE NEED SOME WAY TO GET THE 'ORDER' OF THE CHECKBOXES SELECTED. CURRENTLY 'i' JUST SHOWS THE TOTAL NUMBER OF CHECKBOXES SELECTED


'UPDATE DATABASE CODE GOES HERE (THIS IS NO PROBLEM) BUT NEED CORRECT VALUE OF BASKET NAME TO UPDATE WITH!


rsBasket.MoveNext
i = i + 1


loop until i = (Request.Form("chkbox").Count)
rsBasket.Close







'Code showing the checkbox filed and basket name input field - (this all works)
<INPUT type='checkbox' value='<%= basketid %>' name='chkbox'>
<input type="text" name="sel_quotename" value="<%=quotebasketname%>" maxlength="50" size="50">

'-------------------------------




Thank you very much for any help.
 
Old March 17th, 2006, 05:51 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii matth76!!

say editable field start with 1,2,3 etc
so put checkbox with value 1,2,3,4
these values are unique and is sufficient to indentify which check box
is checked.

<input type=text name="editable1">
<input type=checkbox name="cbox" value=1>

<input type=text name="editable2">
<input type=checkbox name="cbox" value=2>

<input type=text name="editable3">
<input type=checkbox name="cbox" value=3>

now in ur asp code you can find which checkbox is checked
totalcbox=request("cbox")
which gives you comma separated value if 1 and 3 are checked
then its value is 1,3

now for example say your id start with 100 no problem at all
since this time you have 100,101,102
so the best way is to use primary key field or combination of more than one column that can identify your database rows uniquely.

hope this will help you.



Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
checkbox checked by default by html:checkbox sachin.tathod Struts 3 December 4th, 2006 03:41 PM
Open Word Doc from Access - find, find next save donaldmaloney Access VBA 1 May 25th, 2005 11:09 AM
checkbox fcm Access VBA 12 April 15th, 2005 08:15 AM
Create a find and a find and replace in VB.NET snowy0 VB How-To 0 January 26th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.