Click to See Complete Forum and Search --> : java script


anas_a
05-05-2003, 12:00 AM
How to use onchange event in javascript.When i cahnge an item in a drop-down menu i want to show another text on the same page.How can i do database operations using javascript

khalidali63
05-05-2003, 12:16 AM
JavaScript itself does not have the ability to communicate with a DB,you will have to use some server side lprogramming language e.g
java servlets,jsp,php....etc.

onchange event is triggered on a select element when a value is selected from the given options in the select box.
here is the simple code that will display an aler message box when user selects a value.

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Untitled</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-5"/>
<script type="text/javascript">
function Process(val){
alert("You have selected [ "+val+" ]");
}
</script>
</head>

<body>
<form name="form1" action="" onsubmit="">
<select name="listbox" onchange="Process(this.options[this.selectedIndex].value);">
<option value="-1" />Select one
<option value="1" />one
<option value="2" />Two
<option value="3" />Three

</select>
<input type="Button" value="process" onclick="Process()"/>
</form>
</body>
</html>