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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:45:41+00:00 2026-06-13T23:45:41+00:00

I want to make a javascript to be shown if somebody chooses option A

  • 0

I want to make a javascript to be shown if somebody chooses option A to show the javascripts for the A1 , A2 , A3 and if they choose B to show javascripts for the B1 , B2 , B3. So the A and B it will firstly asked as options from a select tag

For example:

<select name="AorB" >
<option value="" selected="selected">Select...</option>
<option value="A" >Option A</option>
<option value="B" >Option B</option>
</select>

I’m using this way of javascript (Error Alerts):

<SCRIPT language=JavaScript>
<!--
function check(form) {
if (form.Password.value == "")
{ alert("Please enter your Password."); form.Password.focus(); return;}
if (form.Password.value.length < 8)
{ alert("Please enter a valid Password."); form.Password.focus(); return;}
form.submit()
}
//-->
</SCRIPT>

P.S: I don’t want to make complications when they choose A to get B option javascripts or reverse.

added – explain: i mean if We select OPTION A there will be shown some Input-s ….and javascript will ask only for the shown input-s so it means OPTION A input-s … but not to ask for OPTION B input-s too even that they’re not shown cause we didnt select OPTION B … i hope i explained a little for you.

  • 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-13T23:45:42+00:00Added an answer on June 13, 2026 at 11:45 pm

    What I understand of your question is that you want a select box and this will determine what fields show up on the form. Then you want the validation script to only validate those fields that show up. This would best be handled with JQuery. Here is some working code to give an example, and a fiddle.

    HTML

    <div id="wrapper">
        <form id="myForm" name="myForm" method="POST" action="http://www.google.com">
            <select id="option" name="option">
                <option value="X">Choose One...</option>
                <option value="A">Option A</option>
                <option value="B">Option B</option>
            </select>
            <div id="optionset-a">
                <p>
                    Input A1: <input name="a1" id="a1" class="option-a" type="textfield" /><br     />
                    Input A2: <input name="a2" id="a2" class="option-a" type="textfield" /><br />
                    Input A3: <input name="a3" id="a3" class="option-a" type="textfield" /><br />
                </p>
            </div>
            <div id="optionset-b">
                <p>
                    Input B1: <input name="b1" id="b1" class="option-b" type="textfield" /><br     />
                    Input B2: <input name="b2" id="b2" class="option-b" type="textfield" /><br />
                    Input B3: <input name="b3" id="b3" class="option-b" type="textfield" /><br />
                </p>
            </div>
            <input type="submit" id="submit-button" name="submit" value="Submit" />
        </form>
    </div>​
    

    JQuery

    $('#optionset-a').hide();
    $('#optionset-b').hide();
    $('#submit-button').hide();
    
    $('#option').change(function() {
        if ($('#option').val() == 'A') {
            $('#optionset-b').hide();
            $('#optionset-a').show();
            $('#submit-button').show();
        } else if ($('#option').val() == 'B') {
            $('#optionset-a').hide();
            $('#optionset-b').show();
            $('#submit-button').show();
        }
    });
    
    $('#submit-button').click(function() {
        var validation = true;
        if ($('#option').val() == 'A') {
            $('.option-a').each(function() {
                if ($(this).val() == '') {
                    $(this).css('border','1px solid red');
                    validation = false;
                }
            });
        }
        if ($('#option').val() == 'B') {
            $('.option-b').each(function() {
                if ($(this).val() == '') {
                    $(this).css('border','1px solid red');
                    validation = false;
                }
            });
        }
        if (validation) {
            document.forms["myForm"].submit();
        } else { alert('Please fill in all fields.'); }
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method: myMethod() {} that I want to make accessible to javascript.
I am traversing a HTML document using javascript DOM. I want make a list
I want to make a variable length array in Javascript. Is this possible. A
I want to make customer route for url which have parameters. <a href='javascript:void(0)' onclick=window.location='<?php
I want to make this: when mouseover on one picture, show its title. I
I want make datetimepicker in my project. Using jquery how it is possible? I
I want make a bash script which returns the position of an element from
I want make interactive application where user launches it and can do various task
Let's say I want make some of my sources publicly available via my blog
I am new android app developer i want make app for tablets and phone

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.