خرید بک لینک
I am trying to figure out how I can process a drop-down list choice from my form. I have two drop-down lists where if you choose a certain option (dog) on the first drop down list (PetType) another drop-down list (Breeds) appears and the Javascript that I accomplished doing that with uses the PetType as it's name. The PHP requires that I use the name attribute but the name atribute is the same for both drop-down lists. So I can't process the form because it doesn't recognize the option that the user chooses. I am new at this. Here is the code that hopefully explains it better:

HTML Form:

Code:

<div class="row">
          <div class="field1">
              <label for="PetType">Pet Type:</label> 
          </div>
          <div class="field2"> 
              <select name="PetType" id="PetType" onchange="return showBreed();">
                  <option value="0">Required</option>
                  <option value="DG">Dog</option>
                  <option value="CT">Cat</option>
                  <option value="RE">Reptile</option>
              </select>
          </div>
        </div>
      <div class="row">
          <div class="field1">
              <label style="visibility: hidden;">Breed:</label>
          </div>
          <div class="field2"> 
              <select name="PetType" id="Breed" style="visibility: hidden;">
                  <option value="0">Choose Breed</option>
                  <option value="AU">Australian Cattle</option>
                  <option value="DA">Dalmation</option>
                  <option value="HO">Hound</option>
                  <option value="PU">Pug</option>
                  <option value="OT">Other</option>
              </select>
          </div>
        </div>

PHP:

Code:

  if ($_POST['PetType'] =='0')
        {
                $PetType = '<span style="color:red;">Pet type not selected.</span>';
        }
        else
        {
        $PetType = $_POST['PetType'];
        }
    if ($_POST['Breed'] =='0')
        {
                $PetType = '<span style="color:red;">Pet type not selected.</span>';
        }
        else
        {
        $PetType = $_POST['PetType'];
        }

JS:

Code:

function showBreed()  {
var selectBox = document.getElementById('petType');
var userInput =selectBox.options[selectBox.selectedIndex].value;
if (userInput =='DG') {
document.getElementById('Breed').style.visibility ='visible';
} else {
document.getElementById('Breed').style.visibility ='hidden';
}
return false;
}

The Results I am getting back:

Grooming Requests

First Name:Bob
Last Name:Bob
Address:1111 Lane
City:New York
State:NY
Zip:00000
Phone Number:000000000
Email:[email protected]
Pet Type:

Notice: Undefined variable: Breed in C:xampphtdocspet-shopadmin.php on line 128
Breed:
Pet Name:tom
Neutered Or Spayed:Spayed
Pet Birthday:10/31

برچسب: نویسنده: آیلین رضوانی تاريخ: يکشنبه 12 آذر 1396 ساعت: 19:12

صفحه بندی