Jump to content

Автовыбор значения select


Nash
 Share

Go to solution Solved by Sig,

Recommended Posts

Здравствуйте! Делаю зависимые select'ы «Город» -> «Список филиалов/адресов». Стоит модуль GeoIP Pro, при выборе города в селект, получаю json адресов из данного города. Но при первой загрузке формы, пока не перевыберешь город в select подгрузка городов не срабатывает. Как сделать, чтобы сразу подгружались адреса, без лишнего перевыбора.

 

              <?php if ($field['type'] == 'select'){ ?>
              <div class="form-group">
                  <label for="sobSelect<?= $field['id_field'] ?>" class="control-label col-sm-12"
                         data-toggle="tooltip" data-original-title="<?php echo $field['tooltip']?  : '' ?>">
                      <?= $field['name'] ?></label>
                  <select name="field[<?= $field['id_field'] ?>][message]" class="form-control" id="sobSelect<?= $field['id_field'] ?>" <?php if($field['id_field'] == '18') { echo 'onchange="loadFranchise(this)"'; } ?>>
                      <?php foreach ($field['options'] as $option){ ?>
                      <label class="radio-inline" >
						<?php if($field['id_field'] == '18') { ?>
							<option value="<?= $option ?>"><?= $option ?></option>
							<?php foreach ($cities as $city) {//заполняем список городов ?>
								<option value="<?= $city['city'] ?>"><?= $city['city'] ?></option>
							<?php } ?>
                        <?php } else { ?>
							<option value="<?= $option ?>"><?= $option ?></option>
						<?php } ?>
                      <?php } ?>
                  </select>
                  <div class="help-block with-errors"></div>
              </div>
              <?php } ?>

				<script>
				$(document).ready(function(){
					var selected = document.cookie.match(/select=(.+?);/);
					if (selected) {
						$('#sobSelect18').val(selected);
					}
					$('#sobSelect18').change(function(){
						document.cookie = "cityFr=" + $(this).val() + ";path=/";
					});
				});
				</script>  
				<script>
					function loadFranchise(select){
						var frSelect = $('select[id="sobSelect19"]');
						$.getJSON('index.php?route=common/header/FranchiseJson', function( franchiseList ){
							frSelect.html('');
							$.each(franchiseList, function( key, val ){
								frSelect.append('<option data-email="'+ val['email'] +'" value="'+ val['address'] +'">'+ val['address'] +'</option>');
							});
						});
					}
				</script>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...