Reset button not working on loading JavaScript

when I remove javascript my reset button works fine but when I load JavaScript its stops working.I have also tried making rest button using jQuery function. I have also tried using input type="reset" value="Reset" but it is also not working. I have tried every thing that I know now I do not know what to do.

Please help

$(document).ready(function c () {
  $("#f").click(function(event){
    $("body").toggleClass("hi");
    event.preventDefault();
  });			
});

$(document).ready(function c1() {
  $("body").click(function(event){
    $("p").toggleClass("hii");
    event.preventDefault();
  });			
});   

//reset funtion using jquery
/*$(document).ready(function re(){
  $("form").click(function(event){
    $("#r").reset(); //reset funtion using jquery
  });	
})*/
body{
  font-size: x-large;
}
h2{
  color: blue;
}
body.hi{
  background:#242424;
  color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div align="right"><input type="submit" id="f" name="night mode" value="night mode" onclick="c()" onclick="c1()"></div>
<h2>contact form</h2>
<form action="mailto:[email protected]" method="post" enctype="text/plain">
  <label  for="company">company's name<br>
    <input type="text" id="company" name="company" autocomplete="companyname" placeholder="name" >
  </label><br>
  <label for="contact_person">contact person<br>
    <input type="text" id="contact_person" name="contact person" autocomplete="contact person" placeholder="name">
  </label><br>
  <label for="email">email <br>
    <input type="email" id="email" autocomplete="email" name="email" placeholder="[email protected]"> <br>
  <label >Subject</label>
  <br>
  <textarea  name="subject" placeholder="Write something.."></textarea><br>
  <button type="submit" value="Submit">Submit</button> reset button 
    I have also tried using input type="reset" value="Reset"
                but it is also not working 
  <button type="reset"  onclick="re()" id="r">Reset</button>
</form>

Answers 1

  • Your problem is that you are writing your $(document).ready() wrong. You do not declare a callable function as a parameter name to ready(). It should look like this:

    $(document).ready(function() {
        function myFunc(event) {
            console.log("Function MyFunc() called");
        }
    });
    

    Next you should only have one $(document).ready(). JavaScript does support multiple ready() declarations, but this just clutters up your code.

    $( document ).ready()


Related Articles