0
 function next()
 {
 alert("form submited");
 return true;
 }
<form onsubmit="return next()" action="add.php" method="post" id="p1">
 <center>Add New Survey</center>
 <p>&nbsp;</p>
 <p align="left"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Title: </p>
 <textarea name="title" cols="2" class="inputs" id="title"></textarea>
 <p align="left"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Discription: (Optional) </p>
 <textarea name="dis" cols="2" class="inputs" id="dis"></textarea>
 <p align="left"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Number of questions: </p>
 <select class="inputs" id="options" onchange="run()" name="options">
 <option value="1" >1</option>
 <option value="2" >2</option>
 <option value="3" >3</option>
 <option value="4" >4</option>
 <option value="5" >5</option>
 </select>
 <br />
 <input type="Submit" value="Next" class="button" name="next"/>
 </p>
 </form>

Here is my code, i want to alert "form submitted" through JavaScript function. when i submit the form, nothing happen. i should alert the string.

user2672165
3,05921 silver badges29 bronze badges
asked May 9, 2014 at 11:08
1
  • 2
    Is the javascript code between <script>function next()...</script> tags? Commented May 9, 2014 at 11:10

1 Answer 1

5

looks like it is because of the button name next which is the same as the function name.

In your console you should be seeing an error Uncaught TypeError: object is not a function

<input type="Submit" value="Next" class="button" name="somethingelse" />

Demo: Problem, Soution

If you log the value of next in the onsubmit handler, it will refer to the next element, see this.

answered May 9, 2014 at 11:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.