How to pass value to previous html page

I have an HTML page with a text box. When you click on the text field, a pop-up window appears, and after clicking the "OK" button, the pop-up window should be closed, and the text field on the first html page should be filled with the value specified in the second HTML. I tried something like this,

one.html

    <form name="form1" >
          <input type="text" name="source" onclick="window.open('second.html')" />
    </form>

second.html

  <input type="button" onclick="{document.form1.source.value='hello';window.close()}" />
+1
source share
2 answers

in your first.html

<form name="form1" >
         <input type="text" id="txt1" name="source" onclick="window.open('second.html')" />
    </form>
<script type="text/javascript" >
function setvalue(args)
  {
    document.getElementByid('txt1').value=args;
  }
</script>

second.html

  <input type="button" onclick="settoparent()" />
<script type="javascript">
  function settoparent()
   {
    if(window.opener.setvalue!=undefined)
     {
      setvalue("textboxvaluefromHTML2");
     }
   window.close()
   }
</script>
+2
source

You have to use

window.opener.$("#yourtextfieldid").val(value);

to achieve this

In your vanilla JS

window.opener.document.yourelementID.fieldname.value="Any value";
-1
source

Source: https://habr.com/ru/post/1534579/


All Articles