Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

help pls

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
================================================================
------------------
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic