check multiple values in an if statement in jquery/javascript

I am trying to if the value of an input box is blank or not by doing the below:

var id = $(this).attr('id').substr(3); var lengthname = $("#input_name_"+id).val().length; var lengthrss = $("#input_rss_"+id).val().length; if (lengthrss!=0 || lengthname!=0) { // do something } else { alert('Values cannot be blank'); }

For some reason it is not doing the OR however if the user enters both values as blanks then the alert comes up??

-------------Problems Reply------------

What you are looking for is an AND operation, not OR. The valid case is when both lengths are non-zero:

if (lengthrss!=0 && lengthname!=0)
{
// do something
}

Alternatively:

if (lengthrss==0 || lengthname==0)
{
alert('Values cannot be blank');
}

For reference: De Morgan's laws

Category:javascript Views:0 Time:2011-09-05

Related post

  • How to check multiple elements in array with one if with JavaScript? 2010-11-01

    I have 1 or more items in an array, for this example let's say they are [65, 66, 67] how can (if it's even possible) do only a single if conditional to check for a match. For example: var keyArray = [65, 66, 67]; if(e.keyCode == any item in keyArray)

  • C# Sql to Linq checking multiple cases 2009-12-11

    How to check multiple cases in Linq ( to classify "over paid","under paid","medium pay") Sql select id,name,salary, case when salary <=1500 then 'under paid' when salary >=3500 then 'over paid' else 'medium pay' end as status from Person Linq v

  • How do I check multiple permissions at the same time on facebook connect? 2009-12-22

    FB.Connect.showPermissionDialog('status_update,offline_access', function(perms) { if(!perms) return callback(false); else return callback(true); }); How do I check multiple permissions at the same time? The above code works only for status_update and

  • How to use mod_Rewrite to check multiple folders for a static file 2010-02-01

    What are the mod_Rewrite rules for checking multiple folder locations for a given file. For instance, if I have a folder structure of: public/ css/ library1/ css/ library2/ css/ and I want requests to /css/somefile.css to first check the public/css/

  • Check multiple textarea fields for value using jquery and then perform a function 2010-09-10

    Basically what I'm trying to accomplish is I want to check multiple dynamic forms on a page. Then if All textareas are empty OR have the default value, perform a function. Otherwise if any of them are not empty without the default value, cancel the f

  • Checking multiple conditions for a string in C# 2011-01-10

    I want to check multiple conditions in a string in C# but it throws error saying Cannot use && for string or boolean if ((duStart.Trim() != "" && duStart.Trim() != null) &&(duEnd.Trim() != "" && duEnd.Trim() != null))

  • checking multiple check boxes automatically 2011-01-28

    I am a PHP Programmer ,I want to know how to programatically check multiple check boxes when another check box is checked by the user.Give me a link or you can give me a code to go through. --------------Solutions------------- This is not possible wi

  • Check multiple items in ASP.NET CheckboxList 2011-07-10

    I try to check multiple values in ASP.NET CheckboxList but I couldn't. I Wrote : chkApplications.SelectedValue = 2; chkApplications.SelectedValue = 6; But it just selects item with value '6' What's wrong ? --------------Solutions------------- you can

  • Check multiple chunks of string against a range in excel in one go 2012-04-20

    I have a range of "Good" values like this: Apple Banana Pear Grape Melon And a range of input data like this ( I could probably hardcode a max of 10 ; separated elements if I had to): Apple; Grape //Good Watermellon //bad Pear; Peach //bad, ideally r

  • Unmatched Access Query to check multiple text 2015-03-01

    So I have field column of data that has multiple Vendor names that are separated by semicolon's that sell a given product that I would like to confirm they match the Vendor's name within a Vendor table. The following Access Query does what I need if

  • Sorting multiple items at the same time using jQuery UI 2009-07-07

    I'm trying to setup a way to sort multiple items at the same time using jQuery UI's Sortable plugin. I have come up with a partial solution, where the checked items go with the drag, but I can't get them all to move positions. Here is what I have: ht

  • Can we write multiple css style in single line in JQuery 2011-11-29

    Can we write multiple css style in single line in JQuery $('.ui-dialog').css("left","475px"); $('.ui-dialog').css("top","215px"); Does we can write this to single line like below $('.ui-dialog').css("'left','475px'","'top','215px'"); // Test --------

  • How can i uncheck multiple select box options by class with jquery? 2012-03-22

    I have multiple multi-select boxes with the same class and i want to unselect all on an event. They have all a div with the same class class_for_all_multi_selects around them. $("#element_to_uncheck_all_options").change(function() { $('.class_for_all

  • How to check whether user has checked at least one checkbox from a group of checkboxes using jQuery/Javascript? 2015-01-11

    I've following HTML code : <ul class='select_ul' style="width:100%"> <li><input name="chk_all_grp_day" id="chk_all_grp_day" type="checkbox"/><span>All</span></li> <li><input name="val[grp_day][]" type="che

  • How to get the checked option in a group of radio inputs with JavaScript? 2008-10-02

    How to get the checked option in a group of radio inputs with JavaScript? --------------Solutions------------- <html> <head> <script type="text/javascript"> function testR(){ var x = document.getElementsByName('r') for(var k=0;k<

  • some jQuery/JavaScript to change bgcolor on input checked 2009-08-14

    Okay, I want some jQuery/JavaScript to show an yellow background-color when its checked. I use class="valgt" to define which checkbox I want to be styled. How do I do this? <td valign="top" class="valgt"> <input type="checkbox" name="check"

  • Check if the user accepted a file download in JavaScript 2010-06-09

    How do I check if the user accepted a file download in JavaScript. Example: If the site pops up a download link, and the web browser asks the user to download the file, how do I determine on that page if the user accepted the download or not? -------

  • issues with getting multiple select param values from jquery, javascript back to perl cgi page 2010-09-20

    I have been working on this for 1 hour with no such luck. Any help would be appreciated. I have a cgi script with which creates these select param values: print "Please select a dkversion to compare : <br><br>"; print "<select name='dk

  • Check File Upload extension (PHP/Jquery/Javascript) 2011-03-10

    As title which of them is better and why? Any weaknesses from doing it? I been hearing that Jquery/Javascript checking is bad and adviced to use PHP but somehow don't know why.... Need some recommend from any of you. Thanks in advance. Anyone see if

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.172 (s). 11 q(s)