How to hide an input field from another page via javascript?

2

Scenery

I have two page .html . In one of the pages I have two options to mark radio both have id , they are XPTO and YPTO e. What I need to do is, when choosing XPTO and then pressing the sign up button, it has to disable a field on the other page.

In my example the field is named LastName , so I was using a condition in javascript If document.getElementById("xpto").textContent is this element, on the other page the field > Surname disappears.

Is there any way to do this even though I'm going to another page next?

My codes below:

PAGE 1: test.html

<body>
    <table border="1">
        <tbody>
            <tr>
                <td><input type="radio"></td>
                <td><input type="radio"></td>
            </tr>
            <tr>
                <td id="xpto">XPTO</td>
                <td id="ypto">YPTO</td>
            </tr>
        </tbody>
    </table>        
    <br /><br />
    <button><a href="test2.html" onclick="disableSobrenome()">CADASTRAR</a></button>
</body>

PAGE 2: test2.html

<body>   


    <form>
        Nome:
        <input type="text" id="nome">
        Sobrenome:
        <input type="text" id="sobrenome">
    </form>

    <a href="test.html">VOLTAR</a>
</body>

Script.js:

function disableSobrenome() {

    if (document.getElementById("xpto").textContent)
    {
        document.getElementById("sobrenome").style.display='none';
    }
}
    
asked by anonymous 27.01.2016 / 20:48

1 answer

2

test.html:

<body>
    <form action="test2.html" method="get"> <!-- FORMULÁRIO SEMPRE UMA BOA OPÇÃO-->
        <table border="1">
            <tbody>
                <tr>
                    <td><input name="opcao" value="xpto" type="radio"></td> <!-- EM RADIO SEMPRE COLOQUE O MESMO NOME E UM VALOR PARA EVITAR MARCAR DOIS -->
                    <td><input name="opcao" value="ypto" type="radio"></td>
                </tr>
                <tr>
                    <td id="xpto">XPTO</td>
                    <td id="ypto">YPTO</td>
                </tr>
            </tbody>
        </table>        
        <br/><br/>
        <button type="submit">CADASTRAR</button> <!-- BOTÃO TENDE A TER AÇÃO PARA FORMULÁRIO -->
    </form>
</body>

test2.html:

<body>   
    <form>
        <p id="nome">Nome:</p> <!-- COLOQUE IDENTIFICADORES EM TUDO -->
        <input type="text" id="nomeInput">
        <p id="sobrenome">Sobrenome:</p>
        <input type="text" id="sobrenomeInput">
    </form>

    <a href="test.html">VOLTAR</a>
</body>

<script>
    var url   = window.location.search.replace("?", ""); //pega url
    var itens = url.split("&"); //separa onde tem o parametro
    var valor = itens[0].slice(6); // 6 pois opcao= tem 6 caracteres
    if(valor == "xpto")
    {
        document.getElementById("sobrenomeInput").style.display='none';
        document.getElementById("sobrenome").style.display='none';
    }
</script>
    
27.01.2016 / 23:46