tags:

views:

3931

answers:

4

I have a contactbook, and a form close to it... For the form, one of the requirements is to fill in the receiver for the message. So when the user clicks on a contact from the contactbook, automaticly the username from the titel-tag should appear in the receiver inpunt in the form.

All help with this is appreciated!!

+1  A: 

A few extra questions, 1) is the <title> tag just the username or does it have extra text in it.

Base code below:

jQuery(function() {
    jQuery('a.addTitleTag').click(function() {
        titleText = document.title; // Placed in new var incase of extra manipulation needed.
        jQuery("input[name='username']").val(titleText);
    });
});
stuartloxton
A: 

SO basically in your example the process goes like this:

  1. User clicks the a link saying username
  2. input with name pmAmne (pmName?) gets filled with 'username' (title attribute of paragraph parent of a link clicked?

If so then the code below should work:

jQuery(function() {
    jQuery('a.addTitleTag').click(function() {
        titleText = jQuery(this).parents('p').attr('title');
        jQuery("input[name='pmName']").val(titleText);
    });
});
stuartloxton
A: 

I think what you want is to get the "Firsname Lastname" part of the p tag with the username tittle attribute.

 $("p[title='username']").find('a').click( function{ //Onclick for the a in the p tag
  contentOfP = $("p[title='username']").html(); //get the content of the p tag, including the <a> tag
  positionOfDash = contentOfP.indexOf('-'); //We need the position of the dash to determine where the 'Firstname Lastname' part of the P tag ends
  names = contentOfP.substr(0, positionOfDash); //Get the start of the P tag withouth the dash
  $("input[name='pmAmne']").val( names ); //Set the value of the input
  return false; //Block the default event for the link so it doesn't jump to the top of the page on long pages
 });

That should do the trick

Pim Jager
A: 

stuartloxton dude nice! Works grate. But it make anather problem for me.

I allready have:

    <script type="text/javascript">
(function update()
    {
      $.ajax(
        {
        type: 'GET',
        url: '/doGet/pmKontakter.php',
        timeout: 2000,

         success: function(data)
         {
           $("#pmKontakter").html(data);
           $("#loadingComponent").html(''); 
           window.setTimeout(update, 10000);
         },

         error: function (XMLHttpRequest, textStatus, errorThrown)
         {
           $("#pmKontakter").html('<h3>Din kontaktlista kunde inte hämtas för tillfället.</h3>');
           window.setTimeout(update, 60000);
         }
        });
    })(jQuery);
</script>

When I use this code abow and your code, your code dosent work.

Adis
How do you implement his code, there should be no collision, although, why are you calling the updae function with the (jQuery) parameter when your update() function doesn't want any parameters?
Pim Jager