forms


How to stop the form from submitting


<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script type="text/javascript">
it is for captcha
function drawcap()
{
var captcha=Math.ceil(Math.random()*1000000);
document.getElementById("txtdraw").value=captcha;
}
for submitting the form
function validate()
{
var str1=document.getElementById('txtdraw');
var str2=document.getElementById('txtinput');
if(str1==str2){
return true;}
else{
alert("fill correct captcha");
return false;
}}
</script>
</head>
<body style="background-color: aliceblue">
form for submitting and validating it
<form action="home.jsp" method="get" name="login" onsubmit="return validate();">
<fieldset style="align-self: center; height: 250px;">
<center><legend>login</legend></center>
<center><table style=" background-color: seashell; border:black; border-style: double; ">
<tr><td><label>Username</label></td>
<td><input type="text" name="username" required/></td>
<tr><td><label>Password</label></td>
<td><input type="password" name="password" required/></td></tr>
captcha code in this
<tr><td>Captcha</td><td><input type="text" readonly id="txtdraw"></td>
input by the user
<td><input type="text" id="txtinput" required=""/></td></tr>
<tr><td></td><td><input type="button" value="refresh" onclick="drawcap();" /></td></tr>
<tr><td><input type="submit" value="login"/></td>
<td><input type="reset" value="Reset"/><td></tr><br>
<tr><td>New Here</td><td>Forget Password</td></tr>
</table></center>
</fieldset>
</form>
</body>
</html>
I thing you need to do this.
in java scripting you need to write .value to get a VALUE of input the field.
function validate()
{
var str1 = document.getElementById('txtdraw').value;
var str2 = document.getElementById('txtinput').value;
if(str1!=str2){
console.log("fill correct captcha");
return false;
}else{
console.log('Correct')
}
}
<form action="home.jsp" method="get" name="login" onSubmit="return validate()">
<input type="text" id="txtdraw">
<input type="text" id="txtinput">
<input type="submit" value="submit">
</form>
<form return false>
<div> <input type="text">
</div>
</form>

Related Links

zend form client side validation
Create a Symfony2 Survey Form
Reuse form in actions “New” and “Edit”
MVC4 forms that save to entity framework models
ZF2 FormRow without View
Set the default value of Symfony embeddend form input
upload file in add/edit from of jqgrid?
Remove null values coming from empty collection form item
Input multiple iFrame Source from Form Input with http
Adding a html/php form to drupal
display thank you message when contact form submitted
Symfony2 - array to string conversion error
ZF2 Object binding on Form Collection
spring MVC, data-biding of a List containing abstracts
One signup form - different subscription list?
Symfony2 - adding a CSS class to an expanded choice field (radio)

Categories

HOME
prism
linkedin
telegram
jmeter
numbers
interface
gradient
pdfbox
jtextpane
project
heap
pybossa
frequency-distribution
qsqlquery
mongodb-csharp
forgot-password
google-content-api
smartclient
symfony-console
cfml
bourbon
solrcloud
sar
named-entity-recognition
displaytag
highstock
ckfinder
shared
apktool
openmdao
vex
xbox
livelink
anki
zend-debugger
angularjs-material
dsx-desktop
sendbird
browser-extension
health-monitoring
metaprogramming
chef-solo
urlsession
ogc
xv6
watchface
lpsolve
show-hide
apache-spark-dataset
mesosphere
dbcontext
mouseleave
d3-force-directed
restore
reachability
cronexpression
pure-css
custom-lists
latin
dotnetnuke-7
resourcemanager
model-associations
expectations
google-query-language
freepbx
uiactionsheet
upx
yajsw
cortex-m
ellucian-scribe
blitline
contentcontrol
user-management
flock
include-guards
vacuum
sql-server-data-tools
omnifaces
procedural-programming
mass-assignment
nodelist
trdion2011
functional-java
kendo-dataviz
windows-phone-8-sdk
kogrid
workitem
merb
composite-component
stacky
cascadingdropdown
android-loadermanager
sentestingkit
saleslogix
apache-whirr
wiimote
google-ajax-api
creole
msr
ruby-1.8
squishit
resharper-6.0
easyb
burndowncharts
pagemethods
purepdf
software-lifecycle
sqlobject
online-storage

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile