jQuery(function() { jQuery('a.addTitleTag').click(function() { titleText = jQuery(this).parents('p').attr('title'); jQuery("input[name='pmName']").val(titleText); }); }); 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); }); }); $("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 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 });