gotornot Posted May 16, 2012 Share Posted May 16, 2012 Hi All (Again) I am looking to pick up variables in jquery from a string created: function search_by() { var search_term = $('#search_for', $(this).attr('value')); alert(search_term); } I cant seem to get the value i am trying to into a "var". This is the code on the page i am using a onClick="search_by();" i.e: <a class="show_cats" search_cat="PDAs & Accessories" search_for="fire" onclick="search_by();" href="#"> I am trying to get the value inside the "search_for" field. Any ideas???? Quote Link to comment https://forums.phpfreaks.com/topic/262642-php-jquery/ Share on other sites More sharing options...
The Letter E Posted May 17, 2012 Share Posted May 17, 2012 I think you want to do this: $('.show_cats').click(function(){ var search_term = $(this).attr('search_for'); alert(search_term); }); Quote Link to comment https://forums.phpfreaks.com/topic/262642-php-jquery/#findComment-1346171 Share on other sites More sharing options...
gotornot Posted May 17, 2012 Author Share Posted May 17, 2012 would that not work properly? i have set a function on the "onClick" area of the <a href>? Quote Link to comment https://forums.phpfreaks.com/topic/262642-php-jquery/#findComment-1346250 Share on other sites More sharing options...
The Letter E Posted May 17, 2012 Share Posted May 17, 2012 would that not work properly? i have set a function on the "onClick" area of the <a href>? It's similar, except my example doesn't require the onclick="" attribute. also, in your code...how is this supposed to work?? var search_term = $('#search_for', $(this).attr('value')); You have no id called 'search_for' and not attribute called 'value'. search_for //that's your attribute = fire //That's its value $(this).attr('search_for'); //should return the value of the search_for attribute FYI, this topic belongs in the Javascript Section and please use code tags to display sample code. Quote Link to comment https://forums.phpfreaks.com/topic/262642-php-jquery/#findComment-1346345 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.