невозможно отобразить выбранные поля рядом? - PullRequest
0 голосов
/ 21 ноября 2018

при выборе полей для возраста ребенка, тогда будут отображаться два поля выбора, но они не будут отображаться рядом.я просто хочу, чтобы они были встроенными, то есть рядом, как первые два поля выборавот мой код.

function addFields() {
	var number = document.getElementById("selected_childs[]").value;
	var childage = document.getElementById("childage");

	//Create array of options to be added
	var array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];

	while (childage.hasChildNodes()) {
		childage.removeChild(childage.lastChild);
	}
	if (number == 1) {
		// statement
		for (i = 0; i < number; i++) {
			childage.appendChild(document.createTextNode("Children Age " + (i + 1)));

			var selectList = document.createElement("select");
			selectList.setAttribute("id", "mySelect");
			selectList.setAttribute("class", "form-control");
			childage.appendChild(selectList);
			childage.appendChild(document.createElement("br"));

			//Create and append the options
			for (var j = 0; j < array.length; j++) {
				var option = document.createElement("option");
				option.setAttribute("value", array[j]);
				option.text = array[j];
				selectList.appendChild(option);
			}
		}
	} else {
		// statement
		for (i = 0; i < number; i++) {
			childage.appendChild(document.createTextNode("Children Age " + (i + 1)));

			var selectList = document.createElement("select");
			selectList.setAttribute("id", "mySelect");
			selectList.setAttribute("class", "form-control");
			childage.appendChild(selectList);
			childage.appendChild(document.createElement("br"));

			//Create and append the options
			for (var j = 0; j < array.length; j++) {
				var option = document.createElement("option");
				option.setAttribute("value", array[j]);
				option.text = array[j];
				selectList.appendChild(option);
			}
		}

	}
}
<!DOCTYPE html>
<html>
   <head>
      <title>Welcome|Home</title>
      <!-- Latest compiled and minified CSS -->
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <!-- jQuery library -->
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <!-- Latest compiled JavaScript -->
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
   </head>
   <body>
      <form method="POST" action="<?php echo base_url(); ?>index.php/dynamically_added_controller/Dynamically/addingValues">
         <div class="this_is_field_wrapper">
            <div class="row">
               <div class="form-group">
                  <div class="col-xs-1">
                     <h6>Options -</h6>
                     <h6 class="#">Adults(12+)</h6>
                     <select id="selected_adults[]" name="selected_adults[]" class="form-control">
                        <option   value="1">1</option>
                        <option selected="selected" value="2">2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5">5</option>
                     </select>
                  </div>
                  <!-- </div>
                     <div class="form-group"> -->
                  <div class="col-xs-1">
                     <h6>1st Room</h6>
                     <h6 class="m_label">Child(0-12)</h6>
                     <select id="selected_childs[]" name="selected_childs[]" value="" onchange="addFields()" class="form-control">
                        <option>--select--</option>
                        <option value="1">1</option>
                        <option value="2">2</option>
                     </select>
                  </div>
                  <!-- </div>
                     <div class="form-group"> -->
                  <div id="childage" class="col-xs-1">
                  </div>
                  <!-- </div>
                     <div class="form-group"> -->
                  <div id="childage" class="col-xs-1">
                  </div>
                  <div class="col-xs-1">
                     <a href="javascript:void(0);" class="this_button_work_for_click_to_add_rooms" title="Add field">Click & Add Rooms</a>                     	
                  </div>
               </div>
               <!-- here ending form group -->
            </div>
            <!-- here ending row -->
         </div>
         <button type="submit" value="submit">click to submit</button>
      </form>
   </body>
</html>

Проблема заключается в том, что при выборе детской комнаты путем выбора поля они отображают два поля, но отображаются сверху вниз.я просто хочу, чтобы они были рядом, как первые два поля выбора.Пожалуйста, помогите спасибо заранее.

1 Ответ

0 голосов
/ 21 ноября 2018

Ваш второй выбор не помещен в правый раздел.Посмотрите, что вы можете сделать:

function addFields() {
var number = document.getElementById("selected_childs[]").value;
var childage = document.getElementById("childage0");

//Create array of options to be added
var array = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];

while (childage.hasChildNodes()) {
    childage.removeChild(childage.lastChild);
}
if (number == 1) {
    // statement
    for (i = 0; i < number; i++) {
        var h = document.createElement("h6");
     var h1 = document.createElement("h6");
  h1.appendChild(document.createTextNode(" "));
  childage.appendChild(h1);

        h.appendChild(document.createTextNode("Children Age " + (i + 1)));
  childage.appendChild(h);

        var selectList = document.createElement("select");
        selectList.setAttribute("id", "mySelect");
        selectList.setAttribute("class", "form-control");
        childage.appendChild(selectList);
        childage.appendChild(document.createElement("br"));

        //Create and append the options
        for (var j = 0; j < array.length; j++) {
            var option = document.createElement("option");
            option.setAttribute("value", array[j]);
            option.text = array[j];
            selectList.appendChild(option);
        }
    }
} else {
    // statement
    for (i = 0; i < number; i++) {
  childage = document.getElementById("childage"+i);
  var h1 = document.createElement("h6");
  h1.appendChild(document.createTextNode(" "));
  childage.appendChild(h1);
  var h = document.createElement("h6");
        h.appendChild(document.createTextNode("Children Age " + (i + 1)));
  childage.appendChild(h);

        var selectList = document.createElement("select");
        selectList.setAttribute("id", "mySelect");
        selectList.setAttribute("class", "form-control");
        childage.appendChild(selectList);
        childage.appendChild(document.createElement("br"));

        //Create and append the options
        for (var j = 0; j < array.length; j++) {
            var option = document.createElement("option");
            option.setAttribute("value", array[j]);
            option.text = array[j];
            selectList.appendChild(option);
        }
    }

}

}

Добавьте числа в DIV вашего ребенка:

 <div id="childage0" class="col-xs-1">
              </div>
              <!-- </div>
                 <div class="form-group"> -->
              <div id="childage1" class="col-xs-1">
              </div>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...