Pass values within frameset

1

I have two pages, where it receives data by typing the product name and description:

<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
    Código:
    <input name="campo1" id="campo1" type="text">

    Descrição: 
    <label name="descrproduto" id="descrproduto">
    </label>
</form>
</body>
</html>

And this, which will send data to the previous one:

<html>
<head>
    <meta charset="utf-8">
    <script> function levarcodigo( codigo,descricao )

       {top.opener.document.getElementById("campo1").value = codigo;
        top.opener.document.getElementById("descrproduto").innerHTML = descricao;}
    </script>
</head>
<body bgcolor="grey">
    <a href="javascript:levarcodigo(1010,'Cafeteira');">1010-Cafeteira</a>
    <a href="javascript:levarcodigo(1020,'Jogo de panelas');">1020-Jogo de panelas</a>
    <a href="javascript:levarcodigo(1030,'Jogo de taças');">1030-Jogo de taças</a>
    <a href="javascript:levarcodigo(1040,'Churrasqueira');">1040-Churrasqueira</a>
</body>
</html>

They work on separate pages but how do I make them work within frames?

    
asked by anonymous 30.04.2018 / 20:20

1 answer

0

You can select the frame that will receive the value by id . Just put the two iframe s with this basic structure:

<iframe id="frame1" src="p1.php"></iframe>
<iframe src="p2.php"></iframe>

Where p1.php has the field and div that will receive the values. p2.php is where the links are.

In p2.php , you will use this script:

<script>
function levarcodigo( codigo,descricao ){
   // seleciona o iframe com o id "#frame1" na página-mãe
   var iFrame1 = top.document.body.querySelector("#frame1");
   iFrame1.contentDocument.getElementById("campo1").value = codigo;
   iFrame1.contentDocument.getElementById("descrproduto").innerHTML = descricao;
}
</script>

p1.php and p2.php are just examples of page names. Change to the ones you want to use.

    
30.04.2018 / 20:56