•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 374,013 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,704 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 21351 | Replies: 4
![]() |
•
•
Join Date: May 2005
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Hey everyone,
I've got a recordset of terms in my page. I know the recordset has all the terms from the sql table within it because i can get it to print just fine to screen.
I need to put the recordset into an array. That way, a script that finds as you type will work in the textbox. I cannot figure out how to get the recordset into the array properly. the script works fine with the included arrays, so I know there isn't a problem with anything, but my ability to get these terms into the array correctly :o )
<%@ page language="java" import="java.sql.*,java.lang.String" %>
<%@ include file="Connections/webcat.jsp" %>
<%
Driver Driverkeywords = (Driver)Class.forName(MM_webcat_DRIVER).newInstance();
Connection Connkeywords = DriverManager.getConnection(MM_webcat_STRING,MM_webcat_USERNAME,MM_webcat_PASSWORD);
PreparedStatement Statementkeywords = Connkeywords.prepareStatement("SELECT term FROM dbo.WDINterm ORDER BY term ASC");
ResultSet keywords = Statementkeywords.executeQuery();
boolean keywords_isEmpty = !keywords.next();
boolean keywords_hasData = !keywords_isEmpty;
Object keywords_data;
int keywords_numRows = 0;
%>
<html>
<head>
<script language="javascript" type="text/javascript" src="actb.js"></script>
<script language="javascript" type="text/javascript" src="common.js"></script>
<script>
var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin');
var custom2 = new Array('something','randomly','different');
// this is where i want to put the array of my terms, the two arrays
// above are demo arrays, but hard coded, not loaded from a database query like i would like to achieve
</script>
</head>
<body>
//this is some garbage i put in the page to make sure the values were indeed loading the recordset, indeed they are
<%
while (keywords.next()) {
out.println("'");
out.println(keywords.getString("term"));
out.println("'");
out.println(",");
}
keywords.close();
%><BR>
//this is the text box that as a user types in something, based up an array, it will auto-complete similar to Google Suggest's functionality
<input type='text' style='font-family:verdana;width:300px;font-size:12px' id='tb' value=''/>
<script>
var obj = actb(document.getElementById('tb'),customarray);
//setTimeout(function(){obj.actb_keywords = custom2;},10000);
</script>
</body>
</html>
So again, how can i take those items from the recordset and fill an array? Especially one in the format like:
var custom3 = new Array('term1fromquery','term2fromquery','term3fromquery');
Thanks for any help you can give me!
I've got a recordset of terms in my page. I know the recordset has all the terms from the sql table within it because i can get it to print just fine to screen.
I need to put the recordset into an array. That way, a script that finds as you type will work in the textbox. I cannot figure out how to get the recordset into the array properly. the script works fine with the included arrays, so I know there isn't a problem with anything, but my ability to get these terms into the array correctly :o )
<%@ page language="java" import="java.sql.*,java.lang.String" %>
<%@ include file="Connections/webcat.jsp" %>
<%
Driver Driverkeywords = (Driver)Class.forName(MM_webcat_DRIVER).newInstance();
Connection Connkeywords = DriverManager.getConnection(MM_webcat_STRING,MM_webcat_USERNAME,MM_webcat_PASSWORD);
PreparedStatement Statementkeywords = Connkeywords.prepareStatement("SELECT term FROM dbo.WDINterm ORDER BY term ASC");
ResultSet keywords = Statementkeywords.executeQuery();
boolean keywords_isEmpty = !keywords.next();
boolean keywords_hasData = !keywords_isEmpty;
Object keywords_data;
int keywords_numRows = 0;
%>
<html>
<head>
<script language="javascript" type="text/javascript" src="actb.js"></script>
<script language="javascript" type="text/javascript" src="common.js"></script>
<script>
var customarray=new Array('an apple','alligator','elephant','pear','kingbird','kingbolt', 'kingcraft','kingcup','kingdom','kingfisher','kingpin');
var custom2 = new Array('something','randomly','different');
// this is where i want to put the array of my terms, the two arrays
// above are demo arrays, but hard coded, not loaded from a database query like i would like to achieve
</script>
</head>
<body>
//this is some garbage i put in the page to make sure the values were indeed loading the recordset, indeed they are
<%
while (keywords.next()) {
out.println("'");
out.println(keywords.getString("term"));
out.println("'");
out.println(",");
}
keywords.close();
%><BR>
//this is the text box that as a user types in something, based up an array, it will auto-complete similar to Google Suggest's functionality
<input type='text' style='font-family:verdana;width:300px;font-size:12px' id='tb' value=''/>
<script>
var obj = actb(document.getElementById('tb'),customarray);
//setTimeout(function(){obj.actb_keywords = custom2;},10000);
</script>
</body>
</html>
So again, how can i take those items from the recordset and fill an array? Especially one in the format like:
var custom3 = new Array('term1fromquery','term2fromquery','term3fromquery');
Thanks for any help you can give me!
•
•
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation:
Rep Power: 4
Solved Threads: 3
Why not:
or similar...
//this is some garbage i put in the page to make sure the values were indeed loading the recordset, indeed they are
var custom3 = new Array(<%
while (keywords.next()) {
out.println("'");
out.println(keywords.getString("term"));
out.println("'");
out.println(",");
}
keywords.close();
%>);or similar...
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
I assume your only question is how to build your javascript line that defines the array, but instead of hard-coding the array items, you want them populated from a SQL query?
If this is the case, then this is a server-side question. And that depends on the language you are using. And this would be the wrong forum.
My suggestion is to iterate your databse recordset building a string where each time you append a comma, a single tick, the value, and another single tick. At the end of the loop, simply strip off the beginning comma. (Look at the substr command or similar in your language of choice.)
Then all you do is write your string into the javascript line as you are outputting the page.
If this is the case, then this is a server-side question. And that depends on the language you are using. And this would be the wrong forum.
My suggestion is to iterate your databse recordset building a string where each time you append a comma, a single tick, the value, and another single tick. At the end of the loop, simply strip off the beginning comma. (Look at the substr command or similar in your language of choice.)
Then all you do is write your string into the javascript line as you are outputting the page.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JSP Marketplace
- sql query problem with MS Access and C# (C#)
- Urgent Help with SQL Query (MySQL)
- C# VS 2005 - SQL Query Parameters to an ODBC DataSource (C#)
- sql query updating problem (Visual Basic 4 / 5 / 6)
- Please help me out with MySQL query (MySQL)
- PHP/SQL query help (PHP)
- Retreiving variables from a sql query into a form (PHP)
Other Threads in the JSP Forum
- Previous Thread: Discussion Board
- Next Thread: OnMouseOver event - show label below item



Linear Mode