Skip to content
Advertisement

Form post not including the select input

I am trying to make a form to register the number of drinks that are taken from the fridge by a certain person.

Currently I have three drinks in my db, meaning that I create 3 select tags and 3 input fields for the number of drinks per drink (e.g. coke, coke zero or coke light). In the code (somewhere earlier), $aantalDrink is set to 3.

This page is entered from selecting a person and a drink (the person is registered in $_POST[‘teacherId’] and the following JS arrays are defined: arr_drinks (all drink names) arr_drinkIds (corresponding drink Ids) arr_initSelectedDrinkId (the id of the initially selected drink).

I want a user to be able to select multiple types of drinks in case he gets multiple drinks for the whole group.

The front end works perfectly. However, when I submit my form, the select (i.e. the chosen drink) is not passed through to the ‘submitted.php’ page. The number of drinks, the hidden variable and submit are posted correctly however.

Note, in “submitted.php” I display all values of $_POST, with: foreach ($_POST as $key => $value) { }.

I am clueless…


HTML [EDIT: HTML instead of PHP creating HTML];

JavaScript

JS:

  • Define options;

  • Set options to all three select tags

  • Set initial option in the first select

  • Disable options that are already selected in one of the select tags

  • When the div with id “NewDrinkType” is clicked, another select tag becomes visible

  • Some small JS to allow a user to increase or decrease the number of drinks per drink.

    JavaScript

Visual aspect:

Regular page:

Consider the following pictures: enter image description here

After submit:

enter image description here

Advertisement

Answer

You are seeing this behaviour because you have made option disabled and disabled value do not get submitted to server . i.e :

JavaScript

Now, to fix this you can add below script to your jquery code :

JavaScript

Above code will get called when user clicked on submit button and then inside this you can remove disabled attribute from your select-box options to make them submit as well .

Quick Demo :

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement