Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:07:07+00:00 2026-05-21T09:07:07+00:00

i have a selection field and when the button #btnaddtocart is selected i want

  • 0

i have a selection field and when the button #btnaddtocart is selected i want to be able to check if the selection (name=quantity) isnt null, if it is then an alert is shown to the user. otherwise not to show anything. the script works but the problem is that if the selection does contain a value the alert still shows. why is this?

here is the html

<select class="select" id="quantity" name="quantity">
<option selected="selected" value="">select one</option>
<option value="data1">data1</option>
<option value="data2">data2</option>
<option value="data3">data3</option>
</select>

here is the js

$(document).ready(function() {

    $("#btnaddcart").click(function()
    {

         if($("input[name=quantity]").val() == null)
          {
               var data = $(this).val();
               alert(data);
          }
      });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:07:07+00:00Added an answer on May 21, 2026 at 9:07 am

    You’re checking the wrong thing, this:

    if($("input[name=quantity]").val() == null)
    

    should be this:

    if($('#quantity').val() == '')
    

    A selector like input[name=... looks for <input> tags with the specified name attribute but you want a <select> element; since your <select> has an id attribute, you can just use an ID selector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question: I have a button field in my gridview, and I want to
I have a selection of elements in a jQuery object. I want to animate
How do I get Set Selection to work in a text field. I have
I want a field to become required only when a specific option is selected
I have a problem related to my previous article css, button selection and html
I have a cell editor that contains a little button and then a textfield
I have a registration form with common registration fields and two multiple selection Lists
I have a selection for some items using a spinner widget. At the moment
I have a selection of a huge set of data and I would like
I have Spatial Selection implemented on Map in my Web Application, which selects the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.