phpjquery-uipostjquery-ui-menu

PHP post jQueryUI menu selection


I have a jQuery UI menu inside a form and I would like to be able to pass the tag attribute as value for my POST in PHP.

Does anybody know how I can do that? I only know how to get that value via JavaScript.

Example:

<form id="cities" name="cities">
   <ul id="menu" style="position:absolute;">
     <li><a href="#" tag="LDN">Lodon</a></li>
     <li><a href="#" tag="MAD">Madrid</a></li>
     <li><a href="#" tag="LYN">Lyon</a></li>
     <li><a href="#" tag="PAR">Paris</a></li>
   </ul>
   ... other input fields...  
   ... a submit button
</form>

I want to POST/GET the tag to the next PHP page.

<?php
   // How can I get the tag or just the menu selection value (Lyon, Paris, etc) 
      and save it to a variable in PHP?
   // I'm more interested in the tag
?>

Thanks in advance for your help,

Cristina


Solution

  • DEMO

    JS code:

    $(function() {
         $( "#menu" ).menu({
             select:function(event, ui){
                 console.log(ui.item);
                 alert("Selected tag = "+$(ui.item).find('a').attr('tag'));
                 $('#tag').val($(ui.item).find('a').attr('tag'));
             }
         });
    });
    

    HTML:

    <form id="cities" name="cities">
       <ul id="menu" >
         <li><a href="#" tag="LDN">Lodon</a></li>
         <li><a href="#" tag="MAD">Madrid</a></li>
         <li><a href="#" tag="LYN">Lyon</a></li>
         <li><a href="#" tag="PAR">Paris</a></li>
       </ul>
        <br style="clear:both;">
        Selected menu tag (hidden field):
            <input type="text" id="tag" name="tag">
    
    </form>