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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get values from database

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
guys,

I have the following simple code. It might look lengthy but i tried to keep it as simple as possible. Just copy and paste the code and you can see it running.

Currently the below example refers to the static lists. But i want the values to be fetched from database.

Can anyone please help me out with this.


Code:
<html>
<head>
<style type="text/css">

div#mlcontent p{line-height:1.4}
div#mlwrapper{float:right;width: 100%;margin-left: -400px}
div#mlcontent{margin-left: 400px}
div#mlleft2{float:right;width:200px}
div#mlleft1{float:right;width:200px}


#catlistdiv{
	float:left;
	/*height:410px;*/
	overflow:auto;	
	width:200px;
	border:1px solid #000;
	background-color:#FFF;	
}
.catlist{
	margin:0px;
	padding:2px;
}
.catlist li{	/* General layout article in list */
	list-style-type:none;
	border:1px solid #999;
	background-color:#EEE;
	height:30px;
	margin:1px;
	padding:2px;
	color:#333;
	cursor:pointer;
}
.catlist li.listMouseOver{
	border:1px solid #000;
	color:#000;
}
.catlist li.listClick{
	border:1px solid #000;
	color:#000;
	background-color:#317082;
	color:#FFF;
}


#sublistdiv{
	float:left;
	/*height:410px;*/
	overflow:auto;	
	width:200px;
	border:1px solid #000;
	background-color:#FFF;	
}
.sublist{
	margin:0px;
	padding:2px;
}
.sublist li{	/* General layout article in list */
	list-style-type:none;
	border:1px solid #999;
	background-color:#EEE;
	height:30px;
	margin:1px;
	padding:2px;
	color:#333;
	cursor:pointer;
}
.sublist li.listMouseOver{
	border:1px solid #000;
	color:#000;
}
.sublist li.listClick{
	border:1px solid #000;
	color:#000;
	background-color:#317082;
	color:#FFF;
}

</style>
<script type="text/javascript">
window.onload = getlists;

var activeList = false;
var clickedList = false;

function getlists()
{
	var mlcobj = document.getElementById('mlwrapper');
	var slobj = document.getElementById('mlleft2');
	slobj.style.visibility = "hidden";
	mlcobj.style.visibility = "hidden";

	listObj = document.getElementById('catlist');
	var lists = listObj.getElementsByTagName('LI');
	for(var i=0;i<lists.length;i++){
		lists[i].onmouseover = mouseoverList;
		lists[i].onclick = selectList;
	}	
}

function mouseoverList()
{
	if(this==clickedList)return;
	if(activeList && activeList!=this){
		if(activeList==clickedList)
			activeList.className='listClick';
		else
			activeList.className='';
		
	}
	this.className='listMouseOver';
	activeList = this;
}

function selectList()
{
var slobj = document.getElementById('mlleft2');
slobj.style.visibility = "visible";
sublistObj = document.getElementById('sublist');
	var sublists = sublistObj.getElementsByTagName('LI');
	for(var i=0;i<sublists.length;i++){
		sublists[i].onmouseover = mouseoverList;
		sublists[i].onclick = selectsubList;
	}	
if(clickedList && clickedList!=this)clickedList.className='listMouseOver';
	this.className='listClick';
	clickedList = this;	

}

function selectsubList()
{
var mlcobj = document.getElementById('mlwrapper');
mlcobj.style.visibility = "visible";
}

</script>
</head>

<body>


<div id="mlwrapper">
<div id="mlcontent">
Please select the category and list to your left.
</div>
</div>
<div id="mlleft2">
	<div id="sublistdiv">
		<ul id="sublist" class="sublist">
			<li id="1">List 1</li>
			<li id="2">List 2</li>
			<li id="3">List 3</li>
		</ul>
	</div>

</div>

<div id="mlleft1">
	<div id="catlistdiv">
		<ul id="catlist" class="catlist">
			<li id="1">Cat 1</li>
			<li id="2">Cat 2</li>
			<li id="3">Cat 3</li>
		</ul>
	</div>
</div>

</body>
</html>

my database tables

table1 -> catid|catname
table2 -> listid|catid|listname

when initally loaded i want to display all category names and then on clicking a category i want to display corresponsing list names and then when a list name is clicked i want to show the content related to current selection, which means i must be able to get hold of the selection values catid and listid.

Please let me know any suggestions if you have.

Thanks

-DNG
 
Seems to me that you need to use some sort of server-side language like: PERL, PHP, ASP, JSP, etc. I don't think there is an ODBC driver that allows JavaScript to connect directly to a database.

Once you choose your server-side language, then find the appropriate forum and ask your question there.

Einstein47
There are no kangaroos in Austria!
[&#91;]Starbase47.com]
 
The only way JavaScript can get to data is via AJAX and even then, you may need a third tool that actually handles the request.

Check out for some articles on AJAX and PHP.

Good luck!


Jose Lerebours


KNOWLEDGE: Something you can give away endlessly and gain more of it in the process! - Jose Lerebours
 
thanks for your suggestions guys...i looked at the scriptilicious library and looks like it would do the job i was looking for...

Thanks

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top