peter-cooper
asked on
How do I Evaluate an expression using OR in jquery
Hello
I need help to evaluate an expression using the OR statement. I have tried || but it produces errors no matter what I try in my expression. What I am trying to do is, if the item_startsWith ?? || if the size_startsWith ?? return the data.
I have posted my code and would be grateful if someone could help with this. Thanks
I need help to evaluate an expression using the OR statement. I have tried || but it produces errors no matter what I try in my expression. What I am trying to do is, if the item_startsWith ?? || if the size_startsWith ?? return the data.
I have posted my code and would be grateful if someone could help with this. Thanks
var dataAdapter = new $.jqx.dataAdapter(source, {
formatData: function(data) {
data.item_startsWith = $("#searchField").val();
data.size_startsWith = $("#searchField").val();
return data;
}
});
You need to look at the substring() function
if (data.item_startsWith.substring(0,2) == '??' || data.size_startsWith.substring(0,2) == '??') {
// True so act here
return data;
}
ASKER
@Leonadis I get 'undefined' in params in firebug. I have also posted the keyup event that uses this data value. Thanks
var oldVal = "";
input.on('keyup', function(event) {
if (input.val().length >= 2) {
if (me.timer) {
clearTimeout(me.timer);
}
if (oldVal != input.val()) {
me.timer = setTimeout(function() {
$("#jqxgrid").jqxGrid('updatebounddata');
}, 1000);
oldVal = input.val();
}
} else {
$("#jqxgrid").jqxGrid('updatebounddata');
}
});
ASKER
@Julian Do I need to include the '??' Thanks
ASKER
@Julian I get 'data.item_startsWith is undefined'. Thanks
Check this:
var values=new Object();
var dataAdapter = new $.jqx.dataAdapter(source, {
formatData: function(values) {
var data = new Array();
values.item_startsWith = $("#searchField").val();
values.size_startsWith = $("#searchField").val();
if(values.item_startsWith!='' || values.size_startsWith!='' ){
data.push(values.item_startsWith);
data.push(values.size_startsWith);
}
return data;
}
});
ASKER
@leonadis Still getting 'undefined'. Thanks
@Julian I get 'data.item_startsWith is undefined'. Thanks
? That's the code you gave us - your question is how to OR to values together and you gave us the two values concerned.
I think we are missing a few pieces of the puzzle here. Take a look at this code
data.item_startsWith = $("#searchField").val();
data.size_startsWith = $("#searchField").val();
You are setting data.item_startsWith and data.size_startsWith to the same value.If that is coming out as undefined then it means #searchField does not exist.
This is further confounded by this line
formatData: function(data) {
Which suggests that data is an input parameter - are you adding to this object with the next two lines?This is a really confusing question - are we supposed to help you populate data.item_startsWith and data.size_startsWith or are you wanting to test those values based on the parameter passed in.
@Julian Do I need to include the '??' ThanksThat comes from your question - I am really confused now.
ASKER
Let me clarify things. I have an input that is called #searchField. This triggers the keyup event (posted above). Initially, the source code only had 'data.item_startsWith = $("#searchField").val(); ' which works ok. What I am trying to do is search 2 fileds in mysql table , so I added the 2nd data.size thinking I could just check in my php backend and evaluate wether size was posted or item.
Hope that is clearer. Thanks
Hope that is clearer. Thanks
ASKER
@Julian This is what you posted. That is where I rasied my comment from. Thanks
if (data.item_startsWith.substring(0,2) == '??' || data.size_startsWith.subst ring(0,2) == '??') {
No - not clear at all
You posted this
Your question title reads
Let us go back a few steps
What is it you are actually asking - your question mentions an OR - what are you trying to OR?
You posted this
What I am trying to do is, if the item_startsWith ?? || if the size_startsWith ?? return the data.That's where the ?? come from.
Your question title reads
How do I Evaluate an expression using OR in jqueryExcept now you are talking about evaluating in the backend.
Let us go back a few steps
What is it you are actually asking - your question mentions an OR - what are you trying to OR?
ASKER
@Julian In the code I have posted I want to search for either item or size. What is happening at the moment is that it is sending the same value for both item and size which is probably the expected behaviour the way it is coded. I need a way to either check in jquery wether they are searching for an item or size. Thanks
Ok but what are we working with what is item and what is size - we have an item_startsWith and size_startsWith and we have #searchField and we have a parameters called data
Nowhere have I seen anything that properly ties these all together
I think what is happening here is you have a clear picture in your head what your app does - but you have not communicated that to us - you have posted bits and pieces (like a jigsaw puzzle) and we are trying to figure out what the picture is.
Tell us what your application does - what it is you are wanting it to do and lets take it from there.
Nowhere have I seen anything that properly ties these all together
I want to search for either item or sizeSearch where / what?
is that it is sending the same value for both item and sizeWhat is 'it'
I need a way to either check in jquery wether they are searching for an item or size.Searching where, who is they (users)
I think what is happening here is you have a clear picture in your head what your app does - but you have not communicated that to us - you have posted bits and pieces (like a jigsaw puzzle) and we are trying to figure out what the picture is.
Tell us what your application does - what it is you are wanting it to do and lets take it from there.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for comment. I have decided to go with 2 inputs as it is the easier option under the circumstance. Many thanks
Open in new window
At the values parameter set your data that coming (I suppose) from a json obj