I want to pass drop down menu item name as an input to a php file. As an example, Tutorials menu item has three drop down menu items (Photoshop,Illustrator,Web Design) and when chick one of them I want to display some data retrive from a database.
To to that I think I have to pass the type of the menu item to a php file. But the problem is how can I get the name of the menu item to a variable.
Is this possible? and how can I do this?
Following is my code for the ‘Tutorials’.
<nav>
<ul>
<li><a href="#">Tutorials</a>
<ul>
<li><a href="#">Photoshop</a></li>
<li><a href="#">Illustrator</a></li>
<li><a href="#">Web Design</a></li>
</ul>
</li>
</ul>
2
Answers
Short answer in JavaScript:
Now you have the clicked item’s name in the selected_menu_item javascript variable.
So, once you have it, you can use it in http calls:
This assumes that you’re using jQuery – a very popular JavaScript library, which has now become a standard on the web. In order to make this example work, put:
In your HEAD section. There’s no need for additional files because it uses a CDN to deliver that file to you from the web.
See JSFiddle to test it for yourself: https://jsfiddle.net/1o49a2rs/
You can achieve this really easily with GET method, You can read further information about the GET Method on PHP.net. Just search GET.
I will try to explain how GET suits your needs simply and convincing, any doubts just ask and I’ll expand the answer with my knowledge about it.
Your links would look something like this:
In your PostData.php file you need to create a small function to GET the information sent with this method. (PostData.php?link=Photoshop): ‘link’ would be your GET variable and youre sending its value as photoshop.
This is a simple way to GET the value in PHP:
I hope this helped!. Good luck and anything else, just ask.