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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:55:01+00:00 2026-05-13T17:55:01+00:00

I am still new at PHP/Javascript/Ajax and am having a very hard time (been

  • 0

I am still new at PHP/Javascript/Ajax and am having a very hard time (been going on for weeks) troubleshooting this problem.

My site has a registration to be a member page that requires all fields to be filled out. This is a website for the Cystic Fibrosis community, so there is a section on the form where you choose your relationship to Cystic Fibrosis. (I have it/ Someone I know has it) If you choose I have it, a drop-down box appears and gives you the option Fibro(male) or Cyster(female). If you choose someone I know, a different drop-down opens with various options(aunt, uncle etc.)

I have a myriad of possible errors that can be made. Passwords don’t match, captcha or terms of use not checked/filled out, etc…therefore the page reloads to display the error message. I have put "echo selected" in all of my option values to have the page load the previously selected information as it should. When you choose ‘I have CF’ this is what happens:

When signing up – if I select "I have CF" the first time but forget to fill in "Cyster or Fibro" I get the error message. THEN when I go back and add in Cyster or Fibro, it continues to tell me, that I need to enter my relation to CF, even though it SHOWS in the box that Cyster or Fibro is selected.

If I’m signing up. Have filled in the relation to CF as "I have CF" AND filled in the "Cyster or Fibro" but get ANY error message (wrong email, passwords don’t match etc) the Cyster or Fibro answer falls out (not there) and if I select it again, it will not accept my choice and keeps saying that "you must choose your relation" even though it’s clearly been selected.

Like I said, I’ve been struggling with this for weeks, and as far as I can tell my code looks correct. I’m thinking it has something to do with the Javascript? Here is my code:

(Please let me know if you need surrounding code to help, thank you)

<tr>


    <td class="left">
           <span style="color:#FF0000;">*</span> Relation to CF:
        </td>
        <td class="right">
            <select name="CFDistance" onchange="switch_distance(this);">
                <option value="null" disabled selected>choose one</option>
                <option value="self" <?php if($_POST['CFDistance'] == "self") { echo "selected"; } ?>>I have CF</option>
                <option value="others" <?php if($_POST['CFDistance'] == "others") { echo "selected"; } ?>>Someone I know has CF</option>
            </select>

            <div id="self_cf_box" class="signup_dropdowns" style="margin:10px 0px 0px 0px;<?php if($_POST['CFDistance'] != "self") { echo "display:none;"; } ?>">
        <span style="color:#FF0000;">*</span> I am a
                <select id="RelationToCF_self" name="RelationToCF" <?php if($_POST['CFDistance'] != "self") { echo "display:none;"; } ?>>
                    <option value="null" disabled selected>choose one</option>
                    <option value="Fibro" <?php if($_POST['RelationToCF'] == "Fibro") { echo "selected"; } ?>>Fibro (male)</option>
                    <option value="Cyster" <?php if ($_POST['RelationToCF'] == "Cyster") { echo "selected";} ?>>Cyster (female)</option>
                    
                </select>
            </div>

Here is the other option (I know someon with CF) that is working just fine:

<div id="others_cf_box" class="signup_dropdowns" style="margin:10px 0px 0px 0px;<?php if($_POST['CFDistance'] != "others") { echo "display:none;"; } ?>">


        <span style="color:#FF0000;">*</span> I am this person's
                <select id="RelationToCF_others" name="RelationToCF" <?php if($_POST['CFDistance'] != "others") { echo "display:none;"; } ?>>
                    <option value="null" disabled selected>choose one</option>
                    <option value="Mom" <?php if ($_POST['RelationToCF'] == "Mom") { echo "selected"; } ?>>Mom</option>
                    <option value="Dad" <?php if ($_POST['RelationToCF'] == "Dad") { echo "selected"; } ?>>Dad</option>
                    <option value="Aunt" <?php if ($_POST['RelationToCF'] == "Aunt") { echo "selected"; } ?>>Aunt</option>
                    <option value="Brother" <?php if ($_POST['RelationToCF'] == "Brother") { echo "selected"; } ?>>Brother</option>
                    <option value="Caregiver" <?php if ($_POST['RelationToCF'] == "Caregiver") { echo "selected"; } ?>>Caregiver</option>
                    <option value="Child" <?php if ($_POST['RelationToCF'] == "Child") { echo "selected"; } ?>>Child</option>
                    <option value="Cousin" <?php if ($_POST['RelationToCF'] == "Cousin") { echo "selected"; } ?>>Cousin</option>
                     <option value="Friend" <?php if ($_POST['RelationToCF'] == "Friend") { echo "selected"; } ?>>Friend</option>
                    <option value="Grandma" <?php if ($_POST['RelationToCF'] == "Grandma") { echo "selected"; } ?>>Grandma</option>
                    <option value="Grandpa" <?php if ($_POST['RelationToCF'] == "Grandpa") { echo "selected"; } ?>>Grandpa</option>
                    <option value="Guardian" <?php if ($_POST['RelationToCF'] == "Guardian") { echo "selected"; } ?>>Guardian</option>
                    <option value="Husband" <?php if ($_POST['RelationToCF'] == "Husband") { echo "selected"; } ?>>Husband</option>
                    <option value="Nephew" <?php if ($_POST['RelationToCF'] == "Nephew") { echo "selected"; } ?>>Nephew</option>
                    <option value="Niece" <?php if ($_POST['RelationToCF'] == "Niece") { echo "selected"; } ?>>Niece</option>
                    <option value="Partner" <?php if ($_POST['RelationToCF'] == "Partner") { echo "selected"; } ?>>Partner</option>
                    <option value="Sister" <?php if ($_POST['RelationToCF'] == "Sister") { echo "selected"; } ?>>Sister</option>
                    <option value="Uncle" <?php if ($_POST['RelationToCF'] == "Uncle") { echo "selected"; } ?>>Uncle</option>
                    <option value="Wife" <?php if ($_POST['RelationToCF'] == "Wife") { echo "selected"; } ?>>Wife</option>
                </select>
        </div>

Here is the JavaScript chunk:

<script type="text/javascript">
    function switch_distance(el) {
        if(el.value == 'self') {
            document.getElementById('self_cf_box').style.display = "block";
            document.getElementById('RelationToCF_self').disabled = false;
            document.getElementById('others_cf_box').style.display = "none";
            document.getElementById('RelationToCF_others').disabled = true;
        }else{
            document.getElementById('self_cf_box').style.display = "none";
            document.getElementById('RelationToCF_self').disabled = true;
            document.getElementById('others_cf_box').style.display = "block";
            document.getElementById('RelationToCF_others').disabled = false;
        }
    }
</script>
  • 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-13T17:55:02+00:00Added an answer on May 13, 2026 at 5:55 pm

    The best way to accomplish this is to use JavaScript for loading the values and validation. I would use a framework to make it easier.

    • ExtJS
    • Dojo
    • JQuery

    are a few of the most well known. These have form validators built in along with AJAX functionality to make your like easier.

    See http://www.extjs.com/deploy/dev/examples/form/dynamic.html

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

Sidebar

Related Questions

I'm still new to ajax and JavaScript, so my apologies for missing something probably
I'm still pretty new to AJAX and javascript, but I'm getting there slowly. I
Still new to Objective C, and I'm having some trouble that I just can't
I still very new using Subversion. Is it possible to have a working copy
I am still very new to Ruby (reading through the Pickaxe and spending most
My focus is on html,PHP,mysql, javascript, css, ajax because that's what many websites need.
still new to the world of linq, and i need some help flatening a
I'm still new to the ASP.NET world, so I could be way off base
I am still new to sharepoint and would like to know if it is
I'm still new to ROR, so pardon the simplicity of the question... So http://www.example.com/controller/:id

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.