Guest User

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

a guest
Feb 27th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  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>
Add Comment
Please, Sign In to add comment