0

I have this code but I'm facing an error in chrome that the load_new_content_dr is not defined.

<html>
<head>
  
<script lang="javascript" src="http://code.jquery.com/jquery-latest.js">
  $(document).ready(function(){

    $("#Dr_name").change(load_new_content_dr()); 
    $("#day").change(load_new_content_day());
});
function load_new_content_dr(){
     var selected_option_value=$("#Dr_name option:selected").val();

     $.post("_add_reservasion.php", {option_value: selected_option_value},
         function(data){ 
              $("#day").html(data);
              alert(data);
       }
     );

     $.post("__add_reservasion.php",
      function(data){
        $("#time").html(data);
        alert(data);

      }
    );
}

function load_new_content_day(){
      var selected_day = $("#day option:selected").val();
  $.post("__add_reservasion.php", {selected_day:selected_day},
    function(data){
      $("#time").html(data);
      alert(data);

    }
  );
}

  </script>
</head>
  <body>
 ...

Some code for connecting database and other stuff...


...
<!--======================doctor name=========================-->
<p>doctor name:</p>
      <select name="Dr_name" id = "Dr_name" form="new" onchange="load_new_content_dr()">
        <option value="null"></option>
        <?php
          while($row = mysqli_fetch_array($table))
          {
            $name = $row["name"];
            if(isset($_POST["Dr_name"]) && $_POST["Dr_name"] == $name)
              echo "<option value =$name selected>$name</option>";
            else
              echo "<option value =$name>$name</option>";

          }
        ?>

      </select><br><br><br>
<!--=========== day===============\\-->
<p>reservation day:</p>
<select name="day" id="day" form="new" onchange="load_new_content_day()"></select><br><br><br>
<!--hour-->
<p>time:</p>
      <select name="time" id = "time" form = "new"></select><br><br>


<input type="submit" value="save">
<input type="submit" name="cancel" value="cancel">
    </form>
  </body>
</html>

It seems that the JavaScript code doesn't work because at first when the page loads it should make some changes but it doesn't :(

6
  • 4
    <'script i'd guess that's why? Commented Feb 13, 2017 at 9:01
  • check your 4th line i.e. after your <head> Commented Feb 13, 2017 at 9:01
  • @FranzGleichmann It's obviously just a typo. Commented Feb 13, 2017 at 9:13
  • @dfsq maybe it's just a typo, but it definitely is not obvious. stranger things have happened in code. Commented Feb 13, 2017 at 9:20
  • @FranzGleichmann It is very obvious because if it was not a typo OP would for sure notice text <' script src="https://code.jquery.com/jquery-latest.js"> $(document).ready(function(){ $("#Dr_name").change(load_new_content_dr()); $("#day").change(load_new_content_day()); }); .... (all his js code) printed on the page. Commented Feb 13, 2017 at 9:29

1 Answer 1

6

If you specify src attribute of the script tag, then its text content is ignored. You should use two script tags instead:

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
  // ...
</script>
Sign up to request clarification or add additional context in comments.

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.