Jump to content

How to use onChange in a Dropdown box?


lopes_andre

Recommended Posts

Hi,

 

I need to develop a code that allows me to choose how I want to see a list of data from the database.

 

For example, I could choose to see "the most recent first" or "most recent last".

 

I have this example on how work the "onChange" event:

 

<html>
<head>
<title>Select Example</title>
<script>
function onSelectChange(){
	var dropdown = document.getElementById("developer");
	var index = dropdown.selectedIndex;
	var ddVal = dropdown.options[index].value;
	var ddText = dropdown.options[index].text;

	if(ddVal != 0) {
		output = "You Selected " + ddText;
	}

	document.getElementById("output").innerHTML = output;
}
</script>
</head>
<body>

<h3>Developers</h3>
<select id="developer" onChange="onSelectChange();">
	<option value="0">the most recent first</option>
	<option value="1">the most recent flast</option>					
</select>

<br /

<div id="output"></div>
</body>
</html>

 

Now I need to apply this to a SELECT from the database that will use this method to list data. I have tried to google it, but I can't find any example.

 

Can someone give me a clue on how to find the way of doing this? There are any examples?

 

Best Regards,

Link to comment
https://forums.phpfreaks.com/topic/216191-how-to-use-onchange-in-a-dropdown-box/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.