The dialog box is invoked by clicking on the input path. How can I determine the input id from which it was called in the dialog box? Ie, we need this functionality: document.getElementById("oldtag").value = val; , only without specifying the input id manually. It is necessary that it determines itself, because there will be more input with other id that use the same dialog box

Connection dialog box:

 <div style='display:none;' id='select_tag'> <?php require_once __DIR__.'/../tag/_tag.php'; ?> </div> 

Form, on click on which opens a dialog box:

 <input id="oldtag" name="Tag[name]" onclick="$('#select_tag').dialog('open');" value="<?=$model_tag->name?>" type="text" required/> 

    2 answers 2

    Use an additional object that will hold the id element being clicked. For all elements for which you need a dialogue call, assign one class, for example, input-with-dialog .

     var popup = { id_clicked : null, openDialog : function(id){ popup.id_clicked = id; $('#select_tag').dialog('open'); } } $(".input-with-dialog").on("click", function(){ popup.openDialog(this.id); } ) 

    Then the id clicked item will be available via popup.id_clicked .

      What if you hang an onclick event on all the inputs with the class .input :

       <input id="oldtag" class="input" name="Tag[name]" value="..." type="text" required/> <script> // когда происходит клик на любом инпуте с классом .input вызывается это событие $(document).on('click', '.input', function() { var input_id = this.id, // это id инпута на который кликнули value = this.value; // это его значение $('#select_tag').dialog('open'); // видимо вызов диалогового окна, я не очень понял // если нужно вставить значение кликнутого инпута в другой инпут $('#other_input').val(value); }); </script> 
      • I didn’t quite understand how this would help me in the _tag.php dialog box _tag.php find out the _tag.php id - Jeque
      • Well, show a piece of your window. where do you need to know him? - toxxxa
      • currently in the window this line is document.getElementById("oldtag").value = val; writes the val variable to the value input id="old_tag" . But manually registering "old_tag" does not fit, you need to auto - detect - Jeque
      • Do you have two input pages with the same id = 'old_tag'? In short, my task is still not clear. now I will update my answer with explanatory comments - toxxxa
      • I'll add another one later with id = "new_tag". So, I need to dial. window it was possible to determine from which input it was called - Jeque