function next()
{
alert("form submited");
return true;
}
<form onsubmit="return next()" action="add.php" method="post" id="p1">
<center>Add New Survey</center>
<p> </p>
<p align="left"> Title: </p>
<textarea name="title" cols="2" class="inputs" id="title"></textarea>
<p align="left"> Discription: (Optional) </p>
<textarea name="dis" cols="2" class="inputs" id="dis"></textarea>
<p align="left"> 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
1 Answer 1
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" />
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
Arun P Johny
389k68 gold badges533 silver badges532 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
default
<script>function next()...</script>tags?