Pass values inside <Frameset>

Asked

Viewed 28 times

1


I have two pages, where this receives data, writing 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:

<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?

  • The two pages inside frames? Then in case, it would be 3 pages?

  • Yes, in total it will be three

1 answer

0


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

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

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

In the 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. Changes to the ones you want to use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.