Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help pls

 
Archu Joshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends i am doing project for opinion poll using servlets .
at frontend i am using html forms to get opinion from user(like other poll on any site, ans may be yes , no or cant'say).
i want to know how to embed java script validations in that html form. b'coz when i am saying button type as "submit" it is not doing any validation & directly submiting null values to servlet. i am saying button type as "button"
it is not at all submitting data
reply soon.

------------------
Archu
 
Kagalkar Praveen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Archu
I suppose u are on right track. Place a button and let the type be Button. Write the function to perform validation and if the return value of the function is true then call submit method.
Suppose the html has the following:
<input type="Button" name="..." onClick="MyFunc1()">
Now write thr function as
<script>
function MyFunc()
{
return(
... some validation to be done here...
}
}
function MyFunc1()
{
if(MyFunc())
{
document.formname.submit();
return true;
}
}
</script>
Hope this will help you.
Bye
Praveen
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The common way to do javascript form validation is to use a submit button like you first tried, with your javascript returning true or false depending on the results of the validation.
For example:

Pay particular attention to the onSubmit in the html. Notice that a value must be reutrned. An onSubmit call that returns false will not submit the form, whereas an onSubmit call that returns true will submit the form. The parameter 'this' passed to the javascript function references the form. Also, the validate function must return true or false.
Hope this helps.
J
 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can use the onSubmit clause in the form tag for final script validation.
The syntax is :
<form name=formname action=actionname method=methodname onSubmit='return functionname()'>
when the form is submitted, the function specified is called. the form is submitted only if the function returns a true value.
Get back to me if you want any more details.
My mail-ID is prabhu_vc@yahoo.com
Bye,
Prabhu.V.C
================================================================
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic