Jump to content
Fórum Script Brasil
  • 0

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


Question

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 to post
Share on other sites

2 answers to this question

Recommended Posts

  • 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 to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149279
    • Total Posts
      645643
×
×
  • Create New...