Note that there are some explanatory texts on larger screens.

plurals
  1. POConditional form not working
    primarykey
    data
    text
    <p>I am new to javascript and I am trying to add a conditional field to a form. I have looked at these posts:<br><br> <a href="https://stackoverflow.com/questions/1992114/how-do-you-create-a-hidden-div-that-doesnt-create-a-line-break-or-horizontal-sp">How do you create a hidden div that doesn&#39;t create a line break or horizontal space?</a>? <br> <a href="https://stackoverflow.com/questions/3961422/conditional-display-of-html-element-forms">conditional display of html element forms</a></p> <p>I have come up with this little example so far which works fine. <br> </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script language="javascript"&gt; function cucu(form){ if(form.check.checked){ document.getElementById("cucu").style.visibility="visible"; } else{ document.getElementById("cucu").style.visibility="hidden"; } } function load() { document.getElementById("cucu").style.visibility="hidden"; } &lt;/script&gt; &lt;/head&gt; &lt;body onload="load()"&gt; &lt;form id="form"&gt; &lt;input type="checkbox" name="check" onclick="cucu(this.form)" &gt; &lt;div id="cucu"&gt; CUCU &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;html&gt; </code></pre> <p>I have tried the same method on a larger side and the only change is that the hidden element is a text field but it just doesnt' work.</p> <p>This is the part of the form:</p> <pre><code>Album: &lt;INPUT TYPE="checkbox" NAME="checkAlbum" onclick="checkAlbum(this.form)" id="idAlbum"&gt; &lt;div id="divAlbum" &gt; Choisir un album : &lt;input type="text" name="Album" list="Albums"&gt; &lt;datalist id="Albums"&gt; &lt;?php $requete = 'SELECT DISTINCT titreAlbum FROM Album'; $resultat = mysqli_query($connexion, $requete); while($row = mysqli_fetch_assoc($resultat)){ echo '&lt;option value="'.$row['titreAlbum'].'"&gt;'; } ?&gt; &lt;/datalist&gt; &lt;br&gt;&lt;br&gt; &lt;/div&gt; </code></pre> <p>My head looks as follows:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html ; charset=UTF-8" /&gt; &lt;title&gt;BLABLA&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="include/styles.css"&gt; &lt;script language="javascript" &gt; function hideElements(){ document.getElementById("divAlbum").style.visibility="hidden"; } function checkAlbum(form){ if(form.checkAlbum.checked){ document.getElementById("divAlbum").style.visibility="visible"; }else{ document.getElementById("divAlbum").style.visibility="hidden"; } } &lt;/script&gt; &lt;/head&gt; </code></pre> <p>I really don't know what the problem is. I've checked the functions again and again. Any suggestions for the possible error? Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload