Ir para conteúdo
Fórum Script Brasil
  • 0

Meu código está dando o erro Uncaught SyntaxError: Unexpected token 'else', alguém poderia me ajudar a resolver?


Everaldo Neto

Pergunta

function billingFunction(){
    if(same.checked == true){
    document.getElementById("billingName").value = document.getElementById("shippingName").value; 
    document.getElementById("billingZip").value = document.getElementById("shippingZip").value;
    } 
} else {
    document.getElementById("billingName").removeAttribute("required"); 
    document.getElementById("billingZip").removeAttribute("required");
}  
 

HTML: 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>Homework</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="css/Homework.css"> 
        <script src="js/Homework.js"></script>
    </head>
    <body>
       
 
<form>
        <fieldset>
            <legend>Shipping Information</legend>
            <label for ="shippingName">Name:</label>
            <input type = "text" name = "shipName" id = "shippingName" required><br/>
            <label for = "shippingZip">Zip code:</label>
            <input type = "text" name = "shipZip" id = "shippingZip" pattern = "[0-9]{5}" required><br/>
        </fieldset>
        <input type="checkbox" id="same" name="same" onchange"billingFunction()"/>
        <label for = "same">Is the Billing Information the Same?</label>
                
        <fieldset> 
            <legend>Billing Information</legend>
            <label for ="billingName">Name:</label>
            <input type = "text" name = "billName" id = "billingName" required><br/>
            <label for = "billingZip">Zip code:</label>
            <input type = "text" name = "billZip" id = "billingZip" pattern = "[0-9]{5}" required><br/>
        </fieldset>
            <input type = "submit" value = "Verify"/>
        </form>
    </body>
</html>
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

function billingFunction(){


    if(same.checked == true){
            document.getElementById("billingName").value = document.getElementById("shippingName").value; 
            document.getElementById("billingZip").value = document.getElementById("shippingZip").value;
    } else {
           document.getElementById("billingName").removeAttribute("required"); 
           document.getElementById("billingZip").removeAttribute("required");
    }

 

}

 

 

Simples: você tinha colocado a chave no lugar errado. O correto deve ser com está aí em cima. 

 

 
 

image.png.5fbd21f7d8504edbc726f6b76cd45742.png

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152k
    • Posts
      651,7k
×
×
  • Criar Novo...