Erollisi Marr - The Nameless

Go Back   Erollisi Marr - The Nameless > NON EQ Stuff (Real life, other games, etc.) > Technical Related


Reply
 
Add/Share Add/Share Thread Tools Display Modes
Old 08-29-2003, 01:15 PM   #1
cnjmorris
Registered User
 
Join Date: Nov 2002
Posts: 925
Default onchange, what am I doing wrong.

Before I forget to say this.. I am only looking for vbscript and .asp here =)

I don't understand why I can't get this to work. What am I doing wrong. Hypothetically choosing a type should populate the books.

It isn't even calling the sub

<%@ LANGUAGE="VBSCript" %>
<%
Sub fillbook(strType)
Set conn2 = Server.CreateObject("ADODB.Connection")
set rs2 = Server.CreateObject("ADODB.RecordSet")
conn2.Open "dns", , "password"
SQLstmt2 = "SELECT * FROM strings"
rs2.Open SQLstmt2,conn2,3,3

for xindex = 0 to book.listcount
book.selectedindex = xindex
book.remove(book.selectedindex)
Next

rs2.Filter = "id = '" & strType & "'"
dim strSplit
strSplit = Split(rs2("string"), ",")
for yindex = 0 to strSplit.Ubound
book.add(strSplit(yindex))
Next
End Sub
%>

<tr>
<td width="16%"><strong>Type:</strong></td>
<td colspan="2"><select name="type" onchange="Call fillbook(type.text)">
<option>Type 1</option>
<option>Type 2</option>
</select></td>
</tr>

<tr>
<td width="16%"><strong>Book: </strong></td>
<td colspan="2"><select name="book" id="book">
</select>
</td>
</tr>
__________________

Catcen, Level 65 Beastlord.

Newbie for life.
cnjmorris is offline   Reply With Quote
Old 08-29-2003, 11:02 PM   #2
Martigan
Supporter
 
Martigan's Avatar
 
Join Date: Nov 2002
Location: San Juan Bautista, CA
Posts: 4,461
Send a message via AIM to Martigan
You are using a client-side event to try and call a server-side method. The two know nothing of each other.

try this...should work...but I didn't debug it or anything...

---------------------------------------------------------------

<%@ LANGUAGE="VBSCript" %>
<%
'establish connection
Set conn = Server.CreateObject("ADODB.Connection")
conn1.Open "dns", , "password"

'get books
set rsBooks = Server.CreateObject("ADODB.RecordSet")
SQLstmt = "SELECT * FROM strings order by id"
rsBooks.Open SQLstmt,conn,3,3

'get types
set rsTypes = Server.CreateObject("ADODB.RecordSet")
SQLstmt = "SELECT distinct id FROM strings order by id"
rsTypes.Open SQLstmt,conn,3,3
%>
<html>
<head>
<script>

var arrBooks = Array(0);
var x=0;

//this function acts as a record
function Book(strType,strBook) {
this.Type = strType;
this.Book = strBook;
}

<%
'server-side script to populate the
'client-side book record array
while not rsBooks.eof
arrSplitBooks=Split(rsBooks.fields("string").value,",")
for y = 0 to arrSplitBooks.Ubound - 1 'is this zero based?
%>
var arrBooks[x++] = new Book("<%=rsBooks.fields("id").value%>","<%=arrSplitBooks(y)% >");
<%
next
rsBooks.movenext
loop
%>

//loads on body load
function bodyLoad()
{
return fillBook("<%=rsTypes("id")%>");
}


//fill the book combo box
function fillBook(strType){

//clear the list
for(;tester.book.length>0;tester.book.remove(tester.book.len gth-1))

//populate the list
for(m=0;m<arrBooks.length;m++) {
//if the correct type, add the book
//to the book combo
if(arrBooks[m].Type==strType) {
tester.book.add(arrBooks[m].Book);
}
}
return true;
}

</script>
</head>
<body onLoad="JavaScript: return bodyLoad();">
<form name=tester>
<tr>
<td width="16%"><strong>Type:</strong></td>
<td colspan="2" name=types>
<%
while not rsTypes.eof
%>
<select name="type" onChange="JavaScript: fillBook(this.value);">
<option value="<%=rsTypes("id")%>"><%=rsTypes("id")%></option>
</select>
<%
rsTypes.movenext
loop
%>
</td>
</tr>
<tr>
<td width="16%"><strong>Book:</strong></td>
<td colspan="2"><select name="book" id="book">
</select>
</td>
</tr>
</form>
</body>
</html>

Last edited by Martigan; 08-30-2003 at 12:06 AM.
Martigan is offline   Reply With Quote
Old 08-30-2003, 02:16 AM   #3
cnjmorris
Registered User
 
Join Date: Nov 2002
Posts: 925
Thanks for the suggestions. The problem I am running into is trying to balance placing too much on each page with creating too many pages.

For example. I am making a quiz site (educational, not like Who Wants to ...).

I was trying to load question categories, have the user choose what book, have the question types load, then have the user add the question, 4 possible choices, the correct answer, and reference (page, chapter, etc) all on one form and it was just going to require to many posts and variable problems.

I am going to greatly decrease my problem by doing the Category, Book, and Type all on one page, then when submitted it will use hidden fields to send that info to the next page where the rest will be done (including actually adding to the database).

Thanks again. I need to learn more about server side/client side. Trying to do a lot of the work client side to keep bandwidth down.
__________________

Catcen, Level 65 Beastlord.

Newbie for life.
cnjmorris is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 01:02 AM.


Powered by: vBulletin. Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.