0

I tried to search something of similar but didn't found.

I have two buttons. If I click one of them i want hide some div but it doesn't work. When i open the page the div d2 and d3 are hidden and it's okay. When i try to click one button it clicks and do nothing. Exists another way to do what i want do? Am I doing something wrong?

<head><title>Aggiungi Studi e Lavori</title>
<script type='text/javascript'>

 function Funz1()
    {
        document.getElementById("d1").style.display = "none";
        document.getElementById("d2").style.display = "none";
        document.getElementById("d3").style.display = "block";

    }


function Funz2()
    {
        document.getElementById("d1").style.display = "none";
        document.getElementById("d2").style.display = "block";
        document.getElementById("d3").style.display = "none";

    }

function checkForm3()
 {
 // Controllo che tutti i campi  della registrazione vengano inseriti
    if(document.registration_form.luogo.value == '' ||
   document.registration_form.titolo.value == '' || 
   document.registration_form.anno.value == '' ||
   )
{
    alert('Inserire tutti i dati contrassegnati con un asterisco');
    return false;
}
// Se arriviamo qui va tutto bene
return true;
}

function checkForm4()
{
// Controllo che tutti i campi  della registrazione vengano inseriti
if(document.registration_form.luogo2.value == '' ||
   document.registration_form.ruolo.value == '' || 
   document.registration_form.anno2.value == '' ||
   )
{
    alert('Inserire tutti i dati contrassegnati con un asterisco');
    return false;
}
// Se arriviamo qui va tutto bene
return true;
}
</script>

<meta charset="utf-8"> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" 

href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
</script>
 <script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
 </script>
 </head>
<body>

<br>
<div id="d1">

<button type="button" onclick="Funz1()" >Aggiungi Esperienza 
Lavorativa</button>              
 <button type="button" onclick="Funz2()" > Aggiungi Esperienza di 
Studio</button> 

</div>



<div id="d2" style= display:none>
<br><form name='studio_form' action='Esperienze.php' method='post' 
 onsubmit='return checkForm3()' >
        <div class='row'>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='titolo'>Titolo</label>
<input type='text' name='titolo'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='anno'>Anno</label>
<input type='text' name='anno'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='luogo'>Luogo</label>
<input type='date' name='luogo'>
</div>



<div class='form-group col-xs-12 col-md-12 col-sm-12 col-lg-12'>                
<input name='submit' type='submit' value='Aggiungi'>     
</div>      

</div>                
</form>
</div>








<div id="d3" style= display:none>
<form name='lavoro_form' action='Esperienze.php' method='post' 
onsubmit='return 
checkForm4()' disabled>
        <div class='row'>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='ruolo'>Ruolo</label>
<input type='text' name='ruolo'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='anno2'>Anno</label>
<input type='text' name='anno2'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='luogo2'>Luogo</label>
<input type='date' name='luogo2'>
</div>



<div class='form-group col-xs-12 col-md-12 col-sm-12 col-lg-12'>                
<input name='submit' type='submit' value='Aggiungi'>     
</div>      

</div>                
</form>
</div>

 </body>   



</html>
2
  • Syntax error in function checkForm4(). if (condition1 || ) {..} Commented May 29, 2018 at 18:32
  • 4
    not just the checkForm4, all checks are finishing the if with || Commented May 29, 2018 at 18:35

2 Answers 2

1

You are finishing your if() with ||. So that code will expect another condition and not a closing tag.

<head><title>Aggiungi Studi e Lavori</title>
<script type='text/javascript'>

 function Funz1()
    {
        document.getElementById("d1").style.display = "none";
        document.getElementById("d2").style.display = "none";
        document.getElementById("d3").style.display = "block";

    }


function Funz2()
    {
        document.getElementById("d1").style.display = "none";
        document.getElementById("d2").style.display = "block";
        document.getElementById("d3").style.display = "none";

    }

function checkForm3()
 {
 // Controllo che tutti i campi  della registrazione vengano inseriti
    if(document.registration_form.luogo.value == '' ||
   document.registration_form.titolo.value == '' || 
   document.registration_form.anno.value == ''
   )
{
    alert('Inserire tutti i dati contrassegnati con un asterisco');
    return false;
}
// Se arriviamo qui va tutto bene
return true;
}

function checkForm4()
{
// Controllo che tutti i campi  della registrazione vengano inseriti
if(document.registration_form.luogo2.value == '' ||
   document.registration_form.ruolo.value == '' || 
   document.registration_form.anno2.value == ''
   )
{
    alert('Inserire tutti i dati contrassegnati con un asterisco');
    return false;
}
// Se arriviamo qui va tutto bene
return true;
}
</script>

<meta charset="utf-8"> 
  <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" 

href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
 <script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> 
</script>
 <script 
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"> 
 </script>
 </head>
<body>

<br>
<div id="d1">

<button type="button" onclick="Funz1()" >Aggiungi Esperienza 
Lavorativa</button>              
 <button type="button" onclick="Funz2()" > Aggiungi Esperienza di 
Studio</button> 

</div>



<div id="d2" style= display:none>
<br><form name='studio_form' action='Esperienze.php' method='post' 
 onsubmit='return checkForm3()' >
        <div class='row'>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='titolo'>Titolo</label>
<input type='text' name='titolo'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='anno'>Anno</label>
<input type='text' name='anno'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='luogo'>Luogo</label>
<input type='date' name='luogo'>
</div>



<div class='form-group col-xs-12 col-md-12 col-sm-12 col-lg-12'>                
<input name='submit' type='submit' value='Aggiungi'>     
</div>      

</div>                
</form>
</div>








<div id="d3" style= display:none>
<form name='lavoro_form' action='Esperienze.php' method='post' 
onsubmit='return 
checkForm4()' disabled>
        <div class='row'>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='ruolo'>Ruolo</label>
<input type='text' name='ruolo'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='anno2'>Anno</label>
<input type='text' name='anno2'>
</div>

<div class='form-group col-xs-12 col-md-6 col-sm-6 col-lg-6'>            
<label for='luogo2'>Luogo</label>
<input type='date' name='luogo2'>
</div>



<div class='form-group col-xs-12 col-md-12 col-sm-12 col-lg-12'>                
<input name='submit' type='submit' value='Aggiungi'>     
</div>      

</div>                
</form>
</div>

 </body>

PS: did you try using the developer tools in the browser, since that throws you an error hinting you Uncaught SyntaxError: Unexpected token ) with a reference to the line where the error was.

Sign up to request clarification or add additional context in comments.

Comments

0

Idk if this could be causing the problem but you have an opening script tag that looks like this

<script 

it is right below the link to your stylesheet

<link rel="stylesheet" 

href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.