|
-
Mar 13th, 2001, 06:04 AM
#1
Hi everyone!
I have an input page on which I have a few selectboxes, each with the same name, but a different value. The selectboxes are placed on the page using an include file. After placing the boxes, I want to make a few of the options checked, but since they are already in my page, I need to use Javascript for that.
I have tried different ways, but none has worked yet. Any ideas?
I have the value of the option I want to have checked in a variable called TheseNeedToBeChecked. These are some of the ways I tried:
=====================================
var CheckThisOne = <%= TheseNeedToBeChecked %>;
myform.hobbies(CheckThisOne).selected = true;
myform.hobbies[CheckThisOne].selected = true;
myform.hobbies(CheckThisOne).selected;
myform.hobbies[CheckThisOne].selected;
myform.hobbies(CheckThisOne).checked = true;
myform.hobbies[CheckThisOne].checked = true;
myform.hobbies(CheckThisOne).checked;
myform.hobbies[CheckThisOne].checked;
=====================================
Any help would be highly appreciated. 
Marcel
-
Mar 13th, 2001, 06:29 AM
#2
Addicted Member
Did you mean you want some of the options in the
Select box Selected by default ?
-
Mar 13th, 2001, 06:46 AM
#3
yes.
-
Mar 13th, 2001, 08:47 AM
#4
Frenzied Member
can you post/mail what you've got so far so I don't have to code an example from scratch?
-
Mar 13th, 2001, 09:04 AM
#5
All I got?
What do you mean "what I got"?
I have all the code, I only need the one line (I hope it's one line anyway) to get the checkbox checked. And when I say checked, I mean so that the "V" is in it, indicating the value is "on".
So the code I have so far is like this:
(the value "Hobbies" in the recordset UserData contains the indexes of the checkboxes I want to have checked, seperated by ";")
===================================
dim strHobbies
strHobbies = UserData("Hobbies")
dim intInPos
intInPos = instr(strHobbies, ";")
dim strHobbyName
dim intIntHobbyID
do while intInPos <> 0
intIntHobbyID = cint(left(strHobbies, intInPos - 1))%>
<script language="javascript">
var HobbyID2Check = <%= intIntHobbyID %>;
myform.hobbies[HobbyID2Check].checked = true;
</script>
<%strHobbies = right(strHobbies, len(strHobbies) - intInPos)
intInPos = instr(strHobbies, ";")
loop%>
=====================================
Hmm.. I see now that I will probably also need to process the last value (when there is just the value left in the string, and no more semi-colons)
Hope you can help. Thanx in advance. 
Marcel
-
Mar 13th, 2001, 09:22 AM
#6
For checking a Checkbox you can use this syntax.
Code:
// JavaScript, Setting the checkbox on
Checkbox.checked = 1;
-
Mar 13th, 2001, 09:22 AM
#7
Frenzied Member
OK, I can't see where on your page the include for writing the check boxes is so I've assumed it is between the body tags.
Here's what I've got anyway.
ch.js
Code:
document.write("<form name=frm1>");
document.write("<input name=hobbies type=checkbox> zxdfgh</input><BR>");
document.write("<input name=hobbies type=checkbox> hgfdhsdfh</input><BR>");
document.write("<input name=hobbies type=checkbox> ryqreyr</input><BR>");
document.write("<input name=hobbies type=checkbox> cxzvbczvxb</input><BR>");
document.write("</form>");
ch.asp
Code:
<%@ Language=VBScript %>
<html>
<head>
<% dim x
x=2
%>
<script LANGUAGE="JavaScript">
function init(){
document.frm1.hobbies[<%=x%>].checked= true
}
</SCRIPT>
</head>
<body onload="init()">
<script language="JavaScript"
SRC="ch.js">
</SCRIPT>
</body>
</html>
is this any help?
-
Mar 13th, 2001, 10:31 AM
#8
Well, not really, coz that wasn't really what I meant..
But for some reason, now all of a sudden, it seems to work (after I realised it used the index instead of the ID of the checkbox to check). I also adjusted the code so it takes care of that last item aswell.
So it works now.
Thanx, guys..
-
Mar 13th, 2001, 10:31 AM
#9
Well, not really, coz that wasn't really what I meant..
But for some reason, now all of a sudden, it seems to work (after I realised it used the index instead of the ID of the checkbox to check). I also adjusted the code so it takes care of that last item aswell.
So it works now.
Thanx, guys..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|