title: Update hidden field - jquery
body: <p>OK, going to try and explain this properly as I think thats why an answer is escaping me and some users are giving me negative replies as they think I have not tried with research to solve this problem.</p>
  
  <p>I have a page where a user is presented with images within a slide viewer. Each item in the slide viewer is inside a LI element. </p>
  
  <p>When a user chooses a slide, and the form is then submitted, I need the script to update a hidden field so I can take which slide they have chosen into a form. Either by updating onclick or when the form is submitted, it matters not when. The hidden field contains the URL of the image shown at that time.</p>
  
  <p>So, the code I currently have is:</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="/js/jquery.easing.1.3.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;!-- this is the slideviewer code --&gt;
  &lt;script src="/js/jquery.slideviewer.1.2.js" type="text/javascript"&gt;&lt;/script&gt;
  
  &lt;!-- this is what I have been trying to update the hidden field --&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
   $( "#wl_add" ).submit( function ( event ) { /* form name and id = wl_add */
   $('input[name="item_pic_url"]').val($('#mygalthree img').attr('src'));
   } );
  });
  &lt;/script&gt;
  
  &lt;!-- the div containing the slide viewer --&gt;
  &lt;div id="mygalthree" class="svw"&gt;&lt;ul&gt;
  &lt;?PHP
  
  foreach($html-&gt;find('img') as $e){ // from simple_html_dom
  
      $image = $e-&gt;src;
  
      echo '&lt;li&gt;&lt;img src="'.$image.'" width=300 alt="" /&gt;&lt;/li&gt;';
  
  }
  
  // the hidden field to be updated - i am presuming needs to be after the loop which feeds the LI elements
  echo '&lt;input type="hidden" name="item_pic_url" value="'.$image.'" /&gt;';
  
  ?&gt;
  
  &lt;/ul&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Or, would it be easier to update the hidden field each time a slide is chosen? below you can see the code for the slideviewer - I would have thought I might be able to add </p>
  
  <blockquote>
    <p>$('input[name="item_pic_url"]').val($('#mygalthree img').attr('src')); </p>
  </blockquote>
  
  <p>when the user clicks? But I cannot find where to add this either and I have tried nearly every line! Slideviewer code:</p>
  
  <pre><code>    jQuery(function(){
     jQuery("div.svw").prepend("&lt;img src='/images/spinner.gif' class='ldrgif' alt='loading...'/ &gt;"); 
  });
  var j = 0;
  var quantofamo = 0;
  jQuery.fn.slideView = function(settings) {
      settings = jQuery.extend({
          easeFunc: "easeInOutExpo",
          easeTime: 750,
          uiBefore: false,
          toolTip: false,
          ttOpacity: 0.9
      }, settings);
      return this.each(function(){
          var container = jQuery(this);
          container.find("img.ldrgif").remove();
          container.removeClass("svw").addClass("stripViewer");       
          var pictWidth = container.find("img").width();
          var pictHeight = container.find("img").height();
          var pictEls = container.find("li").size();
          var stripViewerWidth = pictWidth*pictEls;
          container.find("ul").css("width" , stripViewerWidth);
          container.css("width" , pictWidth);
          container.css("height" , pictHeight);
          container.each(function(i) {
      (!settings.uiBefore) ? jQuery(this).after("&lt;div class='stripTransmitter' id='stripTransmitter" + (j) + "'&gt;&lt;ul&gt;&lt;\/ul&gt;&lt;\/div&gt;") : jQuery(this).before("&lt;div class='stripTransmitter' id='stripTransmitter" + (j) + "'&gt;&lt;ul&gt;&lt;\/ul&gt;&lt;\/div&gt;");            
          jQuery(this).find("li").each(function(n) {
          jQuery("div#stripTransmitter" + j + " ul").append("&lt;li&gt;&lt;a title='" + jQuery(this).find("img").attr("alt") + "' href='#'&gt;"+(n+1)+"&lt;\/a&gt;&lt;\/li&gt;");                                             
          });
          jQuery("div#stripTransmitter" + j + " a").each(function(z) {
          jQuery(this).bind("click", function(){  
          jQuery(this).addClass("current").parent().parent().find("a").not(jQuery(this)).removeClass("current"); // wow!
          var cnt = -(pictWidth*z);
          container.find("ul").animate({ left: cnt}, settings.easeTime, settings.easeFunc);
          return false;
          });
          });
  
  
          container.bind("click", function(e){
              var ui = (!settings.uiBefore) ? jQuery(this).next().find("a.current") : jQuery(this).prev().find("a.current");
              var bTotal = parseFloat(jQuery(this).css('borderLeftWidth').replace("px", "")) +  parseFloat(jQuery(this).css('borderRightWidth').replace("px", ""));
              var dOs = jQuery(this).offset();
              var zeroLeft = (bTotal/2 + pictWidth) - (e.pageX - dOs.left);
  
              if(zeroLeft &gt;= pictWidth/2) { 
                  var uiprev = ui.parent().prev().find("a");  
                  (jQuery(uiprev).length != 0)? uiprev.trigger("click") : ui.parent().parent().find("a:last").trigger("click");                           
              } 
              else {
                  var uinext = ui.parent().next().find("a");
                (jQuery(uinext).length != 0)? uinext.trigger("click") : ui.parent().parent().find("a:first").trigger("click");
              }
          });
  
  
          jQuery("div#stripTransmitter" + j).css("width" , pictWidth);
          jQuery("div#stripTransmitter" + j + " a:first").addClass("current");
          jQuery('body').append('&lt;div class="tooltip" style="display:none;"&gt;&lt;\/div&gt;');
  
  
          if(settings.toolTip){
          var aref = jQuery("div#stripTransmitter" + j + " a");
  
          aref.live('mousemove', function(e) {
          var att = jQuery(this).attr('title');
          posX=e.pageX+10;
          posY=e.pageY+10;
          jQuery('.tooltip').html(att).css({'position': 'absolute', 'top': posY+'px', 'left': posX+'px', 'display': 'block', 'opacity': settings.ttOpacity});
          });
          aref.live('mouseout', function() {
          jQuery('.tooltip').hide();
          });             
          }
          });
          j++;
      }); 
  };
  </code></pre>