Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 6.10 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to assign Session Variables using Jquery and PHP?
  2. <script>
  3.         (function( $ ) {
  4.             $.widget( "ui.combobox", {
  5.                 _create: function() {
  6.                     var self = this,
  7.                         select = this.element.hide(),
  8.                         selected = select.children( ":selected" ),
  9.                         value = selected.val() ? selected.text() : "";
  10.                     var input = this.input = $( "<input>" )
  11.                         .insertAfter( select )
  12.                         .val( value )
  13.                         .autocomplete({
  14.                             delay: 0,
  15.                             minLength: 0,
  16.                             source: function( request, response ) {
  17.                                 var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
  18.                                 response( select.children( "option" ).map(function() {
  19.                                     var text = $( this ).text();
  20.                                     if ( this.value && ( !request.term || matcher.test(text) ) )
  21.                                         return {
  22.                                             label: text.replace(
  23.                                                 new RegExp(
  24.                                                     "(?![^&;]+;)(?!<[^<>]*)(" +
  25.                                                     $.ui.autocomplete.escapeRegex(request.term) +
  26.                                                     ")(?![^<>]*>)(?![^&;]+;)", "gi"
  27.                                                 ), "<strong>$1</strong>" ),
  28.                                             value: text,
  29.                                             option: this
  30.                                         };
  31.                                 }) );
  32.                             },
  33.                             select: function( event, ui ) {
  34.                                 ui.item.option.selected = true;
  35.                                 self._trigger( "selected", event, {
  36.                                     item: ui.item.option
  37.                                 });
  38.                             },
  39.                             change: function( event, ui ) {
  40.                                 if ( !ui.item ) {
  41.                                     var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
  42.                                         valid = false;
  43.                                     select.children( "option" ).each(function() {
  44.                                         if ( $( this ).text().match( matcher ) ) {
  45.                                             this.selected = valid = true;
  46.                                             return false;
  47.                                         }
  48.                                     });
  49.                                     if ( !valid ) {
  50.                                         // remove invalid value, as it didn't match anything
  51.                                         $( this ).val( "" );
  52.                                         select.val( "" );
  53.                                         input.data( "autocomplete" ).term = "";
  54.                                         return false;
  55.                                     }
  56.                                 }
  57.                             }
  58.                         })
  59.                         .addClass( "ui-widget ui-widget-content ui-corner-left" );
  60.  
  61.                     input.data( "autocomplete" )._renderItem = function( ul, item ) {
  62.                         return $( "<li></li>" )
  63.                             .data( "item.autocomplete", item )
  64.                             .append( "<a>" + item.label + "</a>" )
  65.                             .appendTo( ul );
  66.                     };
  67.  
  68.                     this.button = $( "<button type='button'>&nbsp;</button>" )
  69.                         .attr( "tabIndex", -1 )
  70.                         .attr( "title", "Show All Items" )
  71.                         .insertAfter( input )
  72.                         .button({
  73.                             icons: {
  74.                                 primary: "ui-icon-triangle-1-s"
  75.                             },
  76.                             text: false
  77.                         })
  78.                         .removeClass( "ui-corner-all" )
  79.                         .addClass( "ui-corner-right ui-button-icon" )
  80.                         .click(function() {
  81.                             // close if already visible
  82.                             if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
  83.                                 input.autocomplete( "close" );
  84.                                 return;
  85.                             }
  86.  
  87.                             // work around a bug (likely same cause as #5265)
  88.                             $( this ).blur();
  89.  
  90.                             // pass empty string as value to search for, displaying all results
  91.                             input.autocomplete( "search", "" );
  92.                             input.focus();
  93.                         });
  94.                 },
  95.  
  96.                 destroy: function() {
  97.                     this.input.remove();
  98.                     this.button.remove();
  99.                     this.element.show();
  100.                     $.Widget.prototype.destroy.call( this );
  101.                 }
  102.             });
  103.         })( jQuery );
  104.  
  105.         $(function() {
  106.             $( "#combobox" ).combobox();
  107.             $( "#toggle" ).click(function() {
  108.                 $( "#combobox" ).toggle();
  109.             });
  110.         });
  111.         </script>
  112.  
  113.  
  114.  
  115.  
  116. <form method="post">
  117.         <p>Choose Supplier:<select name="SupplierDDL" id="combobox">
  118.         <input type="hidden" name="SupplierId">
  119.         <option value=""></option>
  120.  
  121.         <?php include 'loadSuppliers.php'; ?>
  122.     </select><p>
  123.  
  124.     <p>Number of Items:</label><input type="text" name="ItemsQty"/></p>
  125.         <input name="SupplierSubmit" type="submit" value='Submit'>
  126.         </form>
  127.  
  128.  
  129.  
  130. <script>
  131.     $('input[placeholder], textarea[placeholder]').placeholder();
  132. </script>
  133.        
  134. $('#yourform').append('<input type="hidden" name="supplier_id" value="' + $(this).val + '" />'); // add hidden field
  135.        
  136. $.get('save_session_var.php', {supplier_id: $(this).val});
  137.        
  138. $_SESSION['supplier_id'] = $_GET['supplier_id'];