Reputation: 17906
just recognized strange behaviour in IE9 and i have no idea
ich have this function :
function searchProfile(fieldName, term, page, count) {
jQuery.ajax({type:'POST',
data:'fieldName='+fieldName+'&term='+term+'&id=${id}&page='+page+'&count='+count,
url:'${createLink(action: 'searchProfilByName')}',
global: false,
success:function(data,textStatus){jQuery('#'+fieldName+'_results_div').html(data);},
error:function(XMLHttpRequest,textStatus,errorThrown){}});
};
and it´s called for example :
<div class="button" onclick="searchProfile('netzwerk', netzwerk_searchterm.value, 0, -1)">
chrome FF opera safari excellently "read
"
netzwerk_searchterm.value
but in IE9 or older theres an error
"SCRIPT: 'netzwerk_searchterm' is undefined"
.val()
didn´t work all browsers
anybody got a ninja idea where the error might be ?
thanks in advance
Upvotes: 0
Views: 3219
Reputation: 1931
The fact is, you can move the "netzwerk_searchterm.value" part from method arguments and put it directly in the function, this is what I mean:
function searchProfile(fieldName, page, count) {
var term = $('input#netzwerk_searchterm').val(); //NOTE this
if(!term)
term = '*'; //you can even customhouse the search term
jQuery.ajax({type:'POST',
data:'fieldName='+fieldName+'&term='+term+'&id=${id}&page='+page+'&count='+count,
url:'${createLink(action: 'searchProfilByName')}',
global: false,
success:function(data,textStatus){jQuery('#'+fieldName+'_results_div').html(data);},
error:function(XMLHttpRequest,textStatus,errorThrown){}});
};
This is more readable and works in every browser.
Upvotes: 1
Reputation: 35572
You should be using document.getElementById()
like
searchProfile('netzwerk', document.getElementById('netzwerk_searchterm').value, 0, -1)
Upvotes: 2
Reputation: 7223
Did you define netzwerk_searchterm
as a variable?
I'd say you are trying to access the value of some input field so you should do:
$('input#netzwerk_searchterm').val()
E.g.:
<div class="button" onclick="searchProfile('netzwerk', $('input#netzwerk_searchterm').val(), 0, -1)">
Upvotes: 1
Reputation: 3548
Supposing netzwerk_searchterm
is the id of the field, write this:
<div class="button" onclick="searchProfile('netzwerk', jQuery('#netzwerk_searchterm').val(), 0, -1)">
As you have got jQuery already.
Upvotes: 1