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 8933467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:32:38+00:00 2026-06-15T09:32:38+00:00

I want to create a dynamic alert from a specific input value within each

  • 0

I want to create a dynamic alert from a specific input value within each form. I have many forms on a page. Each alert needs to be slighly different. I am using two of the forms input values to produce the custom message. <input type="hidden" name="on0" value="Size"> & <input type="hidden" name="on1" value="Color">. I have the alert working for the first form on the page, but after the second form, my alert does not match the selected input value of that form. How can I target a specific instance of these input values within the form a user interacts with?

Here is a simplified version of my code showing only two forms:
example on – jsfiddle

<form method="post" class="list1">
<input type="hidden" name="on0" value="Size">
<select name="os0">
<option value="">-- Choose a Size --</option>
<option value="Short">Short</option>
<option value=" Medium">Medium</option>
<option value=" Long">Long</option>                             
</select>
<input type="hidden" name="on1" value="Color">
<select name="os1">
<option value="">
-- Choose a Color --
</option>
<option value="ivory">ivory</option> <option value=" black"> black</option> 
</select> 
<input type="button" value="Add to Cart" class="catalog">                    
</form>
<!-- seconed form start --> 
<hr />
<form method="post" class="list2">
<input type="hidden" name="on0" value="Option">
<select name="os0">
<option value="">-- Choose a Option --</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>                             
</select>
<input type="hidden" name="on1" value="Accent Color">
<select name="os1">
<option value="">
-- Choose a Choose a Accent Color --
</option>
<option value="red">Red</option>
<option value="yellow">yellow</option> 
<option value="orange">orange</option>   
</select> 
<input type="button" value="Add to Cart" class="catalog">                    
</form>

​​
And my js

$(document).ready(function(){

    var size_x = $("input[name='on0']").val();
    var color_x = $("input[name='on1']").val();

    function popWarning() {
        if ($("select[name='os0']").val() === "") {
            alert('Please choose a ' + size_x);
            return false;
        }   
        if ($("select[name='os1']").val() === "") {
            alert('Please choose a ' + color_x);
            return false;
        }
    }
    $("input.catalog").click(function() {
        popWarning();
    });​
});
  • 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-06-15T09:32:39+00:00Added an answer on June 15, 2026 at 9:32 am

    How do you expect the script to know which form (and therefore elements with the same name attribute) you’re talking about without specifying it? Try something like this:

    $(document).ready(function(){
        function popWarning(obj) {
            var $form = $(obj).closest("form");
            var size_x = $form.find("input[name='on0']").val();
            var color_x = $form.find("input[name='on1']").val();
            var sel_os0 = $form.find("select[name='os0']");
            var sel_os1 = $form.find("select[name='os1']");
            if (sel_os0.val() === "") {
                alert('Please choose a ' + size_x);
                return false;
            }   
            if (sel_os1.val() === "") {
                alert('Please choose a ' + color_x);
                return false;
            }
        }
        $("input.catalog").click(function() {
            popWarning(this);
        });
    });
    

    Working example:

    http://jsfiddle.net/7YJ63/6/

    This way, popWarning is able to grab the parent form from the input.catalog that triggered it by click, via obj (this passed in). Then, all elements/values are found with find because you know that the elements you’re looking for are a descendent of the form.

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

Sidebar

Related Questions

I want to create a dynamic select input (dropdown menu) from JSON. I have
I have a page that needs to create dynamic form fields as often as
I want to create dynamic tabPages in TabControl. In each tabPage I create dataGridView
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i
I have less experience with Java Swing and I want to create a dynamic
I want to create a dynamic datadriven application for practice purposes. If I have
I want create MenuStrip dynamic (in winform C#.Net 4.0) From Database (SQL Server) and
I want to create dynamic UITextField with different object name.I have shown the code
I have a page in which I create dynamic controls via OnInit. On the
I want to create an Observable Array from a Dynamic Model that is basically

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.