how to set input value based on sending anchor using jQuery

I've got a list of OpenID's, and I'd like to populate an input field based on the sending anchor.

Basically the goal will be to populate the input with "Google" if the first button is clicked, "Yahoo!" for the second, etc.

Does anyone know how I would do this?

            <div>
                <div class="openid openid_large_btn google-large"> <a href="#" class="openid_btn" ><span>Google</span></a></div>
                <div class="openid openid_large_btn yahoo-large"><a href="#" class="openid_btn" ><span>Yahoo!</span></a></div>
                <div class="openid openid_large_btn myopenid-large"><a href="#" class="openid_btn"><span>myOpenID</span></a></div>
                <div class="openid openid_large_btn aol-large"><a href="#" class="openid_btn"><span>AOL</span></a></div>
                <div class="openid openid_large_btn facebook-large"><a href="#" class="openid_btn"><span>facebook</span></a></div>
            </div>

<script>
    $('.openid_btn').click(function () {

//I'd like to set this to the info contained within the <span> tags
        $("#openid_identifier").val("???"); 


        $('#OpenIDForm').submit();
    });
</script>

Answers


Like this

$('.openid_btn').click(function () { 
    $("#openid_identifier").val($("span", $(this)).text());  
    $('#OpenIDForm').submit(); 
}); 

Need Your Help

How to fix table header in Extjs 4.2

header grid fixed extjs4.2

I want to fix my table/grid header in my ExtJs 4.2 application, so that the header is allways visible, while scroling. The main grid in my application has a fixed header and is implemented as in th...

Use bash script $1 argument in awk command

linux bash shell awk

I want to create a bash script that takes an argument and using awk to print if

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.