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

  • Home
  • SEARCH
  • 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 3358832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:47:58+00:00 2026-05-18T02:47:58+00:00

I have a php form and I want to display or hide certain fields

  • 0

I have a php form and I want to display or hide certain fields dependant on what I select in a drop down.
I have code below which works:

$(document).ready(function() {
    $('div.pupname').hide();
    $('div.pupnid').hide();

    if ($("#perpetrator").val == "1") {
        $('div.pupname').hide();
        $('div.pupid').show();
        else {
            $('div.pupid').hide();
            $('div.pupname').show();
        }

        $("#perpetrator").change(function() {
            if ($("#perpetrator").val() == "1") {
                $('div.pupname').hide();
                $('div.pupid').show();
                else {
                    $('div.pupid').hide();
                    $('div.pupname').show();
                }
            });

        });

I now want to have a multi row block which I am generating using php so I can generate the divs as pupid1, pupid2 etc. and the field $m_perpetrator as an array. I’ve tried a few ways of accessing the array but can’t get anything to work. I thought he following might be along the correct lines for accessing the elements of the array but it does nothing.

if ($("#m_perpetrator[1]").val == "1") {
    $('div.pupname1').show();
    $('div.pupid1').hide();
}
else {
    $('div.pupid1').show();
    $('div.pupname1').hide();
}

Added

Here is a snippet of the HTML

<td><select name="m_perpetrator[1]" id="m_perpetrator[1]">
<option value="1">Current</option>
<option value="2" selected>Former</option>
<option value="3">Parent/Carer</option>
</select>
</td> 
<td>Name</td>
<td>
<div class="pupname1">
<input type="text" size=60 name="m_pupil_name[1]" value="JOHN SMITH">
</div>

<div class="pupid1">
<select name="m_pupil_id[1]"  onchange="getXtras(this)">
<option value="">Select .....</option>

So basically this is a multi row form and on each row if Current is selected then I want to display pupil_id if anything else is selected then I want to display pupil name.
For processing the input I run round the array m_perpetrator[] using php
Jim

  • 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-18T02:47:58+00:00Added an answer on May 18, 2026 at 2:47 am

    Not completely sure what you need. Do you have multiple elements with the same id m_perpetrator?

    Use class instead you should do it this way

    if ($($(".m_perpetrator")[1]).val() == "1") {
        $('div.pupname1').show();
        $('div.pupid1').hide();
    }
    else {
        $('div.pupid1').show();
        $('div.pupname1').hide();
    }
    

    Otherwise what is m_perpetrator in html?

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

Sidebar

Related Questions

I have code with the following form: <?php function doSomething{ //Do stuff with MySQL
I have a multi-lingual page where I want to display form validation error in
I have a page where I want to display a form if the user
I have buy.php with a form where you enter items, quantity, shipping data, etc.
I have an HTML form - with PHP, I am sending the data of
The basics: I have a contact form that uses php to validate the forms.
I have a rewrite rule of the following form: RewriteRule ^foo/([a-zA-Z0-9]+)$ foo.php?arg=$1 [qsa,nc] It
I have a form with labels and input fields. When clicking into a field
I have a PHP form for uploading files and it works fine and displays
I have a PHP form that needs some very simple validation on submit. I'd

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.