How do i call servlet from javascript after validation the javascript

Hi ,
Can anyone tell me how to call a servlet after the javascript is being validated. Here is my code to validate javascript i need to call a servlet inorder to save the data into the same form. I tried calling through the action method in the form but its directly taking me to the servlet but not validating the form. Is there any way that i can validate the form first then call the servlet.
Thanks in advance.
<html>
<head>
<title>Online Blog</title>
<script language ="javascript" type ="text/javascript">
function myfunction()
var mesg = "";
var dmesg = "";
var dnumber = 0;
var number = 0
var Blogstr = document.onlineblog.BlogName;
var Fnamestr = document.onlineblog.FirstName;
var Lnamestr = document.onlineblog.LastName;
var Datestr = document.onlineblog.Dateformat;
var Imagestr = document.onlineblog.uploadimage;
var Imageval = Imagestr.value;
var flength = parseInt(Imageval.length) - 3;
var fext = Imageval.substring(flength,flength + 3);
var Dateval = Datestr.value;
var Dformat = /^\d{2}\/\d{2}\/\d{4}/; //checks the date format.
//splits date into mm, dd , yyyy format.
var m = Dateval.split("/")[0];
var d = Dateval.split("/")[1];
var y = Dateval.split("/")[2];
//Get today's date (removes time).
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
//checks if month and date are displayed in mm, dd format and if not sets to mm,dd.
if (mm <10)
mm = '0'+mm;
if (dd <10)
dd = '0'+dd;
//checks if name of the blog is empty
if(Blogstr.value == "")
number = number+1;
mesg += "\n" + number + "Name of the blog";
//checks if value of Frist Name is empty;
if(Fnamestr.value == "")
number = number+1;
mesg += "\n" + number + "First Name";
//checks if value of Last Name is empty;
if(Lnamestr.value == "")
number = number+1;
mesg += "\n" + number + "Last Name";
//checks if value of date is empty;
if(Datestr.value == "")
number = number+1;
mesg += "\n" + number + "Date of mm/dd/yyyy format";
//checks if value of image field is empty;
if(Imagestr.value == "")
number = number+1;
mesg += "\n" + number + "select an image";
//displays all the error messages.
if (number > 0)
alert ("Please enter the following" + mesg);
return false;
//checks if entered date format is mm/dd/yyyy
if(!Dformat.test(Dateval))
dnumber = dnumber +1;
dmesg += "\n" + dnumber + "please enter a valid date(mm/dd/yyyy)";
//checks if date is greater than 12 and is 2 digits.
if ((m>12 && m<100) || (m> = 100 && m<1000) || (m==0))
dnumber = dnumber+1;
dmesg += "\n" + dnumber + "Enter valid month(mm)";
//checks if month has 31 or 30 days and is in dd format.
if (((d>30) && (d<100) && (m == 04 || m == 06 || m == 9 || m == 11)) || ((m == 01 || m == 03 || m == 05 || m == 07 || m == 08 || m == 10 || m==12) && (d >31) && (d<100)) || d == 0)
dnumber = dnumber+1;
dmesg += "\n" + dnumber + "Enter valid date(dd)";
//checks if month has 28 or 29 days and wheather is a leap year or not.
if((m == 02 && d>29 && y%4 == 0) || (m == 02 && d>28 && y%4 != 0))
dnumber = dnumber+1;
dmesg += "\n" + dnumber + "Enter valid date(dd)";
//checks if entered date is prior to the current date.
if((m == mm && d == dd && y == yyyy) || (y > yyyy)|| (d>=dd && m>=mm && m<=12 && y==yyyy) || (d<=dd && m>mm && y == yyyy && m<=12))
dnumber = dnumber + 1;
dmesg += "\n" + dnumber + "Please enter a date prior to the current date";
if (y == 0 || y < 1000 || y>9999) //checks if year is zero and is a 4 digit number.
dnumber = dnumber + 1;
dmesg += "\n" + dnumber + "Enter a valid year(yyyy)";
//checks if image format is jpg or gif.
if(fext != "jpg" && fext != "gif")
dnumber = dnumber + 1
dmesg += "\n" + dnumber + "You can only upload gif or jpg images.";
if(dnumber>0)
alert("please check the followin error messages"+dmesg);
return false;
</script>
<style type="text/css">
.style1 {color: #FF0000}
body {
     background-color: #FFCCFF;
h2 {
     color: #CC3399;
h1 {
     color: cc3399;
.style2 {
     font-family: Arial, Helvetica, sans-serif;
     font-weight: bold;
.style5 {color: #000000; font-family: "Times New Roman", Times, serif;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><body>
<h1 align="center">Webloggers space</h1>
<p align="center">Home
<p>
<h4> Please enter the following details to register.</h4>
<p> <b>Note:</b> All fields marked with <span class="style1">*</span>(astrick)
are compulsory.</p>
<form action="servlet/BlogServlet" name="onlineblog" onsubmit = "return myfunction()" method="post">
<table width="60%" border="0" cellspacing="5" cellpadding="2">
<tr>
<td><span class="style1">*</span>Name of the Blog</td>
<td><input type="text" name="BlogName"/></td>
</tr>
<tr>
<td><span class="style1">*</span>First Name</td>
<td><input type="text" name="FirstName"/></td>
</tr>
<tr>
<td><span class="style1">*</span>Last Name</td>
<td><input type="text" name="LastName"/></td>
</tr>
<tr>
<td><span class="style1">*</span>Date(mm/dd/yyyy)</td>
<td><input type="text" name="Dateformat"/></td>
</tr>
<tr>
<td>Category</td>
<td><select name="catagory" size="1">
<option></option>
<option>Business</option>
<option>Education</option>
<option>Entertainment</option>
<option>Food</option>
<option>Hobbies</option>
<option>Personal</option>
<option>Politics</option>
<option>Sports</option>
</select></td>
</tr>
<tr>
<td>Enter your text here:</td>
<td><textarea name="textarea" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td><span class="style1">*</span>Upload Image <span class="style5">(.jpg
          or .gif)</span></td>
<td><input type="file" name="uploadimage" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="save">
<input type="reset" name="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>

Your javascript code contains a syntax error. That's why the function isn't being called. Take a look at this line in your code.
if ((m>12 && m<100) || (m> = 100 && m<1000) || (m==0))Notice the space between > and =. Remove that space.
m >= 100

Similar Messages

  • How can I call contacts from my list without the country code that is registered with that contact?

    I have all my contacts registered with a country code. When I want to make calls from my iphone, I do not want the phone to dial the country code, but only the area code. How can I make that happen?

    Your 3G backup contains your contacts already, you don't need to sync them to Outlook or anything just restore the backup file from the 3G onto the 4S and you should be good to go.
    This kb article should help:
    http://support.apple.com/kb/ht1414

  • How do I install Cs3 from disk, after trashing the trial version?

    I've made the mistake of trashing the trial version of Cs3 that I had on my imac a few years ago.
    Now I'd like to install photoshop cs3 on my imac as my other computer is out dated and I get the error message that CS3 is conflicting with CS3 on the computer.
    I realise it was a mistake to trash the trial. Is there anything I can do?

    Download the cleaner tool from the following location and select "CS3" from the pop-up menu. http://www.adobe.com/support/contact/cs5clean.html
    It will show you all CS3 products installed on your machine and will also allow you to remove them selectively. Select the trial build and click "Cleanup".
    Or if you have no other CS3 or CS4 application installed on your machine you can just click "Clean All CS3/CS4" to clean your machine.
    Then try to install Photoshop CS3.

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • Calling servlet from a java program

    Hi
    I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
    Can anyone help me to start with this.
    any suggestion is welcome.

    You have to establish a URLConnection with servlet from your java program.
    URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
    URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
    ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
    oos.writeObject(your file object);-------------------------------------------------
    In the servlet u can get the strings using request.getParameter("str1");
    In the servlet u can get the strings using request.getParameter("str2");
    file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
    hope this helps :)

  • Calling Servlet from a java prog?

    Hi all,
    I am calling servlet from a java prog (Java Agent in Lotus Notes) by using URL and URLConnection object. how can i trigger the Servlet By using doPost method .I have to send some parameter also.
    Thanx
    Muthu

    you need to open a connection to the servlet. Then you must call getInputStream() and getOutputStream() and use them in any way you see fit. I was trying this before and could not get POST to work unless I openned the input stream from the servlet. Strange... but doGet worked without openning the input stream???
    // open a connection....
    // write to the servlet
    servletConnection.getOutputStream().write("whatever");
    servletConnection.getOutputStream().flush();
    servletConnection.getOutputStream().close();
    // grab what the servlet sends back, required to do a post.
    byte [] in = new byte[100];
    servletConnection.getInputStream().read(in);
    servletConnection.getInputStream().close();

  • Calling servlets from main()?

    Hi
    I would like to know that while calling servlets from another class having main(), how can we set the type of request i.e. put, post or get?
    Thanks

    use the method - setRequestMethod( "POST") of HttpURLConnection for setting the method to POST.Similarly for other methods..
    You could find [url http://java.sun.com/developer/JDCTechTips/2004/tt0210.html#2]this useful

  • How do I keep itunes from putting things into the cloud after I've downloaded them?

    Hello - Not everyone lives in Silicon Valley or New York City.  I have a relatively slow internet connection so it takes about 2 hours to download a 45-minute tv episode.  Yesterday I did that, and today I went to watch it and it had been put back in the cloud!  "No problem," says Apple, "You can download it again."  It takes f**** 2 hours to download it again.  How can I keep Itunes from putting things I've already downloaded back into the cloud?

    How do I keep itunes from putting things into the cloud after I've downloaded them?
    You don't. They are in the cloud as soon as you make a purchase. As in immediately/right now. They don't get uploaded from yoru computer to the cloud.
    Did you delete it after you watched it?

  • Very urgent: call servlet from JSP

    Hello,
    I'm facing a problem in invoking a servlet from a JSP having the JSF components.
    The application has a text field to implement ajax for search functionality in the database .I have written a servlet to make the database connection and fire the querry.
    Ajax implementation in a js file is called on every keyup event in the jsp file,and
    a call is given to the servlet from the ajax methode.
    The function in the js file is as follows:-
    function getPersonByFirstNameXML( firstName ) {
        if (!firstName) {
            clearPersonByFirstNameXML();
        } else {   
            var url = BASE_URL + "/servlet/get_PersonsXML";
            alert(url);
            return new AJAXRequest("post", url, "firstName=" + encode(firstName), processGetPersonByFirstNameXML);
    }Im getting the myAJAX.status value as 500.
    I think I'm not able to access the servlet properly.
    what changes do i need to make in the we.xml file ?
    and what should be the url to be passed.
    Please provide me a sloution to the above problem as it is very urgent else if anybody is aware of a readymade JSF componet with search functionality freely available please let me know.
    PS:
    The sample application named RedirectionExample which makes use of a servlet and would be of help to you. You can find the tutorial on the following page:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    is not available as stated in some of the suggestions by Author: mayagiri
    Thanks for any help.
    Abhi

    the status 500 generally means either HTTP server internal error or that execution of CGI script or servlet aborted with error.
    It can be reasonably supposed that the request reaches the servlet, ie. that "url" value points to some existing servlet, otherwise most probably the status value would be 404.
    To test that the servlet is working i'd try to access it using some simple html page with form like this (with {BASE_URL} replaced by real value):
    <form method=post action={BASE_URL}/servlet/get_PersonsXML>
    <input type=text name=firstName>
    <input type=Submit>
    </form>

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • How to invoke a servlet from MDB

    Hi,
    Can someone please tell me how to invoke a servlet from MDB. Actually I want to have a MDB that will invoke a servlet that takes arround ~3 minutes to process and send the response back to MDB. Any small code snippet on invoking a servlet.
    Thanks

    nope. this is probably a bad design.
    but here's a hint: whenever you have a question like this, start browsing the javadocs. chances are there's a class that might help you.
    i'd recommend that you look at this:
    http://java.sun.com/javase/6/docs/api/java/net/HttpURLConnection.html
    %

  • How do I keep URLs from printing after Events?

    Version 3.0.8 (1287) - How do I keep URLs from printing after Events?

    Open the Pages preferences > uncheck Automatic detect email and web addresses

  • How to block calls & texts from one telephone number

    How to block calls & texts from one telephone number

    Call number blocking is done only by the carrier. Some carriers allow users to input numbers to be blocked on a website.
    Verizon allows users to list up to five numbers to be blocked for free for 90 days by entering them in the users My Verizon site. I've found that 90 days has been sufficient to discourage most nuisance calls. But Verizon also provides a service ( for a fee) that will permanently block a number.
    So contact your carrier to see what they offer.

  • How do I stop iTunes from starting up in the other active Windows sessions?

    I have multiple (3) user accounts on a windows (Vista) computer. When I start iTunes from one account iTunes wants to also start up on each of the active windows accounts and continues to attempt to start iTunes after some time period (90 seconds?).
    I get a error screen on the attempts for the User that should not be starting iTunes that reads:
    You cannot open the application "iTunes" because another user has it open.
    Ask the other user to quit the application, then try again.
    I want iTunes to run within only one account. How do I stop iTunes from starting up in the other active accounts?

    Connect iPhone - iTunes will launch
    select iPhone in iTunes' left column
    in iTunes' main window untick "Automatically sync ..."

  • How can I move apps from one computer to the other?

    How can I move apps from one computer to the other?
    (preferably without iCloud)

    Backup your iTunes library to an external drive and onto the other computer
    http://support.apple.com/kb/ht1751

Maybe you are looking for

  • Disp+work is stopped........

    Hi, Sap experts. Hope all are doing good!!!!!!! Disp+work is stopped.... i'm new to sap.... please help me how to solve this issue..... i will provide dev_disp log below.. trc file: "dev_disp", trc level: 1, release: "720" sysno      19 sid        SA

  • Loading multiple tables with SQL Loader

    Hi, I want to load multiple tables from a single data file using SQL Loader. Here's the basic idea of what I want. Let's say I have two tables, table =T1 and table T2: SQL> desc T1; COL1 VARCHAR2(20) COL2 VARCHAR2(20) SQL> desc T2; COL1 VARCHAR2(20)

  • I having problems saying i need to upgrade my flash player and when i do nothing happens

    I cant seem to get flash player to work. I just got a new macbook pro a couple days ago and some videos and programs dont work. It say "missing plu in" the ill click on a link and get directed to adobe flash. I downloaded it but still nothing works.

  • Converting from a shuffle to a nano

    Hi Just got a Nano the other day and already have the latest version of itunes on my notebook < running windows xp> and I have been able to load songs onto the shuffle for the last yr. Now I want to load them onto the Nano and I'm not getting anywher

  • Downloading DesignWebPremium_CS6_LS16.dmg Content verification failure (Content invalid)

    we are trying to download the DMG package of CS6 and it seems to be corrupted on Adobe servers? We tried Akamai several times, downloading it to Windows PC (via Firefox 13.0.1) or Apple Mac Pro (Safari on OSX 10.7) with same result: Content verificat