JUJU0802
JUJU0802

Reputation: 3

Uncaught TypeError: sujet is not a function

Here I tried everything and nothing works and I do not understand why.

Then the goal and when users selects other I want to display an input topic but I have this error

Screenshot of error message: "sujet is not a function"

  <div class="input-field col s12">
    <select id="selectsujet" onchange="sujet()">
      <option value="" disabled selected>Choisissez une option</option>
      <option value="1">Demande Posteur</option>
      <option value="2">Demande 365 days</option>
      <option value="3">Report User</option>
      <option value="4">Demande de debannissement</option>
      <option value="5">Autre... (préciser)</option>
    </select>
    <label>Sujet</label>
</div>
<div id="sujet" style="display: none" class="row">
    <div class="col s12 m12 l12">
        <div align="center" class="input-field col s12">
          <input id="sujet" type="text" class="validate">
          <label for="sujet">Sujet</label>
        </div>
    </div>               
</div>


<script>
    function sujet() {
        s = document.getElementById("selectsujet").value;
        if(s == "5")
        {
            $("#sujet").show();
        }else{
            $("#sujet").hide();
        }
    }
</script>

Upvotes: 0

Views: 45

Answers (2)

Nick Prozee
Nick Prozee

Reputation: 2913

I'll post this as a new answer because my first answer still relates to your "first" problem (you edited post).

Working example
(Might not be the exact correct code as you want it but it shows a working version and you should edit it to your needs)

Extra (thanks to @Teemu)
You have 2 id's with sujet in your question, those should be unique

<!doctype html>

<html lang="en">
<head>
  <meta charset="utf-8">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  </script>
</head>

<body>
  <div class="input-field col s12">
    <select id="selectsujet" onchange="sujet()">
      <option value="" disabled selected>Choisissez une option</option>
      <option value="1">Demande Posteur</option>
      <option value="2">Demande 365 days</option>
      <option value="3">Report User</option>
      <option value="4">Demande de debannissement</option>
      <option value="5">Autre... (préciser)</option>
    </select>
    <label>Sujet</label>
</div>
<div id="sujet" class="row">
    <div class="col s12 m12 l12">
        <div align="center" class="input-field col s12">
          <input type="text" class="validate">
          <label for="sujet">Sujet</label>
        </div>
    </div>               
</div>
<script>
 function sujet() {
        s = document.getElementById("selectsujet").value;
         if(s == "5")
    {
        $("#sujet").show();
    }else{
        $("#sujet").hide();
    }
    }</script>
</body>
</html>

Upvotes: 1

Nick Prozee
Nick Prozee

Reputation: 2913

You should put your sujet() function in the script tag:

<script>
function sujet() {
    s = document.getElementById("selectsujet").value;
    if(s == "5")
    {
        $("#sujet").show();
    }else{
        $("#sujet").hide();
    }
}
</script>

Upvotes: 0

Related Questions