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????
PHP & JQUERY
Moderator: General Moderators
Re: PHP & JQUERY
You can't use Javascript syntax (jQuery is a Javascript library) in PHP. PHP is running in the server and has no contact with Javascript running in the browser. What you can do is send the Javascript, just like HTML, to the browser to be used after it receives the web page. To do that, you can use the echo command.
- Grizzzzzzzzzz
- Forum Contributor
- Posts: 125
- Joined: Wed Sep 02, 2009 8:51 am
Re: PHP & JQUERY
well for starters $('#search_for'); doens't refer to anything, the # selector is used for ids of elements, you don't have an element with an ID of 'search_for'gotornot wrote: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????
$(this).attr('value'), where has 'this' come from. To be able to use 'this' like what i think you're doing, you'd have to have
Code: Select all
$('.show_cats').click(function(){
alert($(this).attr('search_for'));
});
I imagine your code should look like
Code: Select all
function search_by() {
var search_term = $('.show_cats').attr('search_for');
alert(search_term);
}