Jump to content

How to use onChange in a Dropdown box with PHP?


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?

 

Best Regards,

Link to comment
Share on other sites

I am assuming you have no knowledge of ajax. Ajax makes it so you can access data without reloading a page. Basically you are going to need to use the ORDER BY mysql statement and send a variable through ajax so that a secondary php page can read it. I would reccomend moving this post to the General Discussion -> AJAX Help you will find a lot more helpful answers there.

Thanks,

Colton Wagner

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.