Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

jquery: on click, add text from title-tag to an input box

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 1.64 KB  |  views: 15  |  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. jQuery(function() {
  2.     jQuery('a.addTitleTag').click(function() {
  3.         titleText = jQuery(this).parents('p').attr('title');
  4.         jQuery("input[name='pmName']").val(titleText);
  5.     });
  6. });
  7.        
  8. jQuery(function() {
  9.     jQuery('a.addTitleTag').click(function() {
  10.         titleText = document.title; // Placed in new var incase of extra manipulation needed.
  11.         jQuery("input[name='username']").val(titleText);
  12.     });
  13. });
  14.        
  15. $("p[title='username']").find('a').click( function{ //Onclick for the a in the p tag
  16.   contentOfP = $("p[title='username']").html(); //get the content of the p tag, including the <a> tag
  17.   positionOfDash = contentOfP.indexOf('-'); //We need the position of the dash to determine where the 'Firstname Lastname' part of the P tag ends
  18.   names = contentOfP.substr(0, positionOfDash); //Get the start of the P tag withouth the dash
  19.   $("input[name='pmAmne']").val( names ); //Set the value of the input
  20.   return false; //Block the default event for the link so it doesn't jump to the top of the page on long pages
  21.  });
  22.        
  23. <script type="text/javascript">
  24. (function update()
  25.     {
  26.       $.ajax(
  27.         {
  28.         type: 'GET',
  29.         url: '/doGet/pmKontakter.php',
  30.         timeout: 2000,
  31.  
  32.                 success: function(data)
  33.                 {
  34.                   $("#pmKontakter").html(data);
  35.                   $("#loadingComponent").html('');
  36.                   window.setTimeout(update, 10000);
  37.                 },
  38.  
  39.                 error: function (XMLHttpRequest, textStatus, errorThrown)
  40.                 {
  41.                   $("#pmKontakter").html('<h3>Din kontaktlista kunde inte hämtas för tillfället.</h3>');
  42.                   window.setTimeout(update, 60000);
  43.                 }
  44.         });
  45.     })(jQuery);
  46. </script>