There are several links with attributes. Attribute values ​​are set via php and they are all different. Below is the form that is called when you click on any of these links. It is necessary to transfer the value of the data-model of the current link to one of the inputs of this form.

This is a template for a modal window, the parameters of the button component are passed to it in an array, including the $ arParams ['MODEL_NAME'] parameter I need.

<?$arInfo = array( "IBLOCK_ID" => $arParams['IBLOCK_ID'], "VALIDATE_EMAIL" => $arParams['VALIDATE_EMAIL'], "MODEL_NAME" => $arParams['MODEL_NAME'],);?> <form action="/.ajax.php" name="popup_form" id="popup_form_<?= $arInfo['ID_FORM'] ?>" class="popup_form" enctype="multipart/form-data" method="POST" onsubmit=""> <input type="hidden" name="iblock_id" value="<?= $arInfo['IBLOCK_ID'] ?>" /> <input type="hidden" name="validate_email" value="<?= $arInfo['VALIDATE_EMAIL'] ?>" /> <input type="hidden" name="model_name" value="<?= $arInfo['MODEL_NAME'] ?>" /> <div class="block <?= $INPUT_TYPE ?>"> <div class="input"> <input type="text" rel="<?= $arResult['PROPERTY_LIST_FULL'][$propertyID]['CODE'] ?>" id="form_text_<?= $propertyID ?>" class="input" name="PROPERTY[<?= $propertyID ?>][<?= $i ?>]" size="25" value="" /> <input type="submit" value="Отправить" /> </form> </div> 

A modal window is called by an onclick, parameters are passed to show_popup from the array above, this part of the code resulted in what it looks like in generated form in html

 <a href="javascript:void(0);" data-model="<?=$arParams['MODEL_NAME']?>" class="link_popup" rel="nofollow" onclick="show_popup({id: '16', model-name: 'Kia'}); $('#form_text_323').val($(this).attr('data-model')); return false;" return false;">Получить предложение</a> 

The MODEL_NAME parameter is transmitted to the data-model, transmitted along with other data to show_popup, and directly in the modal emptiness itself.

  • Do you need a similar one? - Rustam Gimranov
  • Yes. Issue the markup question and the show_popup method, if any. - Rustam Gimranov
  • Updated the question body as I could - Anastasia
  • show_popup function itself implemented or not? Why the third parameter does not pass the value? - Rustam Gimranov

1 answer 1

Since there is little information, and not everything is clear from the markup, the answer will be distracted. But within the theme: transferring different data to one input field.

 var i var input = document.getElementById('form_text') var modal = document.getElementById('modal_box') var buttons = document.getElementsByClassName('link_popup') function processEvent(event) { var dataset = event.target.dataset modal.style.display = '' // Обратите внимание: свойство пишется по правилу camelCase. input.value = dataset.modelName event.preventDefault() console.log(dataset.id, dataset.model, dataset.modelName) } for (i = 0; i < buttons.length; i++) { buttons[i].addEventListener('click', processEvent) } 
 <p><a href="#" data-id="16" data-model="200" data-model-name="Kia-200" class="link_popup">Получить предложение</a></p> <p><a href="#" data-id="32" data-model="400" data-model-name="Kia-400" class="link_popup">Получить предложение</a></p> <p><a href="#" data-id="48" data-model="800" data-model-name="Kia-800" class="link_popup">Получить предложение</a></p> <div id="modal_box" style="display:none;"> <form> <input id="form_text" type="text" class="form_text" value="" /> <input type="submit" value="Отправить" /> </form> </div> 

  • Thank you very much! Everything works, and before that, when I tried, too. Just at some point, the value of the input nulls, it remains to find this piece of code - Anastasia
  • And is this input field $('#form_text_323') exactly on your page? - Rustam Gimranov
  • Yes, and I see that value takes the right value after the click is made, but is immediately cleared. - Anastasia
  • And the form is not cleared up due to the fact that the page is somehow reloaded? - Rustam Gimranov
  • Not. The page does not reload. The element with the form is created on the page when clicking on one of the buttons, and after closing the modal window it remains in the house-tree with display: none. I managed to transfer the necessary values ​​to visible inputs by clicking on the button (when the modal window opens, the necessary data is already placed in the fields), but I could not transfer to the hidden inputs (value gets the value for a second, but then immediately clears) Anastasia