Results 1 to 6 of 6

Thread: My form can't submit...kindly help

  1. #1
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default My form can't submit...kindly help

    Dear forum members,

    I'm trying to re-work on my web pages. Alas, my old form isn't working anymore...as in it used to be able to submit but now when I press submit, it just stall there.

    Here's my java scripts and the form.

    Code:
    <%@ page contentType="text/html; charset=UTF-8" %>
    <%
                String strCookieName = "serverMessage";
                String strServerMessage = "";
                Cookie objCookies[] = request.getCookies();
                Cookie objCookie = null;
                if (objCookies != null) {
                    for (int intIndex = 0; intIndex < objCookies.length; intIndex++) {
                        if (objCookies[intIndex].getName().equals(strCookieName)) {
                            objCookie = objCookies[intIndex];
                            strServerMessage = objCookie.getValue();
                        }//if
                    }//for
                    Cookie objKillMyCookie = new Cookie("serverMessage", "");
                    objKillMyCookie.setMaxAge(0);
                    objKillMyCookie.setPath("/");
                    response.addCookie(objKillMyCookie);
                }//if
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Tutors Registration</title>
            <link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen,projection" />
            <link rel="stylesheet" style type ="text/css" href ="style.css">
            <script language="javascript">
                function checkForm(){
                     declare an empty Object variable.
                     var objForm = new Object();
                     var objFullNameTextBox = new Object();
                     var objMessageBox = new Object();
                     var objAddress = new Object();
    
                    var strName = new String("");
                    objForm = document.getElementById("frmData");
                    objFullNameTextBox = document.getElementById("FullName");
                    objMessageBox = document.getElementById("divMessage");
                    objEmail = document.getElementById("Email");
    
                    strName = objName.value;
                    strEmail = objEmail.value;
                    strAddress = objAddress.value;
    
    
                    strEmail = trimData(strEmail);
                    strAddress = trimData(strAddress);
    
                    strName = objFullNameTextBox.value;
                    strName = trimData(strName);
                    if (strName=="" ){
                        strMessage += "Please indicate Name<br>";
                        blnIsAllOkay = false;
                    }
                    if (strAddress=="" ){
                        strMessage += "Please indicate Address<br>";
                        blnIsAllOkay = false;
                    }
    
                       if (blnIsAllOkay==true){
                        objForm.submit();
                    }else{
                        objMessageBox.innerHTML = strMessage;
                    }
    
                    function trimData(pstrData){
                        var intIndex=0;
                        var intRightIndex= pstrData.length -1;
                        while((intIndex < pstrData.length) && (pstrData.charAt(intIndex) == ' '))
                        {intIndex++; }
                        while((intRightIndex > intIndex) && (pstrData.charAt(intRightIndex) == ' '))
                        {intRightIndex-=1;}
                        return pstrData.substring(intIndex, intRightIndex+1);
                    }
                }
                function clearErr() {
                    objMessageBox = document.getElementById("divMessage");
                    objMessageBox.innerHTML = "";
                }
            </script>
        </head>
        <body>
            <div id="wrapper">
                <div id="header">
    
    <form id="frmData" name="frmData" action = "process" method = "post" >
    <table>
                    <tr>
                        <td>Full Name</td>
                        <td><input type="text" id="FullName" name="FullName"></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td><input type="text" id="Address" name="Address" value=""></td>
                    </tr>
    <tr>
                        <td>Email</td>
                        <td><input type="text" id="Email" name="Email" value=""></td>
                    </tr>
    
    
     <td>
                    <input type="button" id="btnSubmit" name="btnSubmit" value="Submit" onclick="checkForm()"/>
                    <input id="reset" type="reset" name="reset" value="reset" onclick="clearErr();"/></td>
            </tr>
        </form>
    Hope someone can point me the way to make it submit...Thanks. Or if my javascript is outdated, please let me know where I can get easy plug-in code like jquery for java - preferably one with checkbox, radio buttons, drop down option etc.

    Thanks.

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    I haven't checked any JavaScript as far as validation goes but you cannot submit a form, and have it processed/do something with the data, with JavaScript alone.
    You would need to use a server-side language, such as PHP, to do that.

    From your markup;
    Code:
    <form id="frmData" name="frmData" action = "process" method = "post" >
    The provided "action" looks incomplete - I would expect it so look more like action="process.php", where it would be posting to a PHP file that contained the code to perform the processing task.

    As this is a re-work of a form that used to submit, it might be that you've edited the markup incorrectly, so have a look for the form processing file on your server, possibly called "process.php", and make sure your form points to that.

    Also check offline backups in case you've deleted the server version.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

  3. #3
    Join Date
    Aug 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    I haven't checked any JavaScript as far as validation goes but you cannot submit a form, and have it processed/do something with the data, with JavaScript alone.
    You would need to use a server-side language, such as PHP, to do that.

    From your markup;
    Code:
    <form id="frmData" name="frmData" action = "process" method = "post" >
    The provided "action" looks incomplete - I would expect it so look more like action="process.php", where it would be posting to a PHP file that contained the code to perform the processing task.

    As this is a re-work of a form that used to submit, it might be that you've edited the markup incorrectly, so have a look for the form processing file on your server, possibly called "process.php", and make sure your form points to that.

    Also check offline backups in case you've deleted the server version.

    So there's nothing wrong with de JavaScript right?

    I am using java so 'process' is ok in java context.

    In any case, I have done umpteen times of debugging on all de codes but just can't submit my form I am thinking of replacing de validation with Jquery for java.

    Does anyone know where to get a free and easy plug in or learn de art of it?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That looks like asp code, the parts with the <% . . . %> brackets around it, is it? If so you can submit to an asp page. But you can submit via javascript, however the results will not be recorded anywhere unless that javascript uses AJAX to call a server side page like PHP or asp to record the results.

    And here, in the script you show, there could be other problems, but the highlighted line has to be a comment (add the red comment tokens):

    Code:
            <script language="javascript">
                function checkForm(){
                     //declare an empty Object variable.
                     var objForm = new Object();
                     var objFullNameTextBox = new Object();
                     var objMessageBox = new Object();
                     var objAddress = new Object();
    
    . . .
    Otherwise the code will not run at all.

    For jQuery validation, there's:

    http://jqueryvalidation.org/

    Oh, and it's javascript, not java - java is something else, yet another server side language.
    Last edited by jscheuer1; 08-12-2013 at 06:07 PM. Reason: details
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by jscheuer1 View Post
    That looks like asp code, the parts with the <% . . . %> brackets around it, is it?
    Actually, I'm not positive, but I think it's JSP. That's where it gets confusing in understanding what the OP is talking about. He could be mentioning Java because he's running JSP; where he says he wants to replace his jQuery validation with Java, he may be saying he wants to transfer the validation responsibilities from client side to server side.

    @OP For these reasons, please be extra clear in what you mean and what you're trying to do.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    He's not currently using jQuery for anything. So I think he wants to perhaps replace his current javascript validation with jQuery validation. As to whether or not that's jsp up at the top there in the <% ... %> bracketed area (could well be), and if so, if they want jQuery for Java (which exists, but isn't really for validation, it looks like it's more for controlling jQuery from the server side, but possibly could be adapted to do form validation), you're right, that's not clear.

    But the current validation is done, or is being attempted to be being done via ordinary javascript, not particularly well written at that. Replacing that with regular jQuery validation would make more sense.

    Oh, and Beverley is right, the action of the form has to be something that will take the data of the form and do something with it. If "process" is something like that, fine. It could possibly be. The way to test that would be to remove the validation code and the onclick event from the submit button. If the form then submits as expected, then "process" is a valid server side script.

    What do you expect to happen when the form successfully submits?

    One further thing for now, generally validation is done using the on submit of the form event, not on the on click of the submit button event.

    Make that another further thing - Even if the current javascript validation can be made to work, and with a fair bit of correction/editing it can (this assumes the asp/jsp part, whatever that is, works OK and that "process" is a valid action for the form):

    Code:
    <%@ page contentType="text/html; charset=UTF-8" %>
    <%
                String strCookieName = "serverMessage";
                String strServerMessage = "";
                Cookie objCookies[] = request.getCookies();
                Cookie objCookie = null;
                if (objCookies != null) {
                    for (int intIndex = 0; intIndex < objCookies.length; intIndex++) {
                        if (objCookies[intIndex].getName().equals(strCookieName)) {
                            objCookie = objCookies[intIndex];
                            strServerMessage = objCookie.getValue();
                        }//if
                    }//for
                    Cookie objKillMyCookie = new Cookie("serverMessage", "");
                    objKillMyCookie.setMaxAge(0);
                    objKillMyCookie.setPath("/");
                    response.addCookie(objKillMyCookie);
                }//if
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Tutors Registration</title>
            <link rel="stylesheet" type="text/css" href="stylesheet.css" media="screen,projection" />
            <link rel="stylesheet" style type ="text/css" href ="style.css">
            <script language="javascript">
                function checkForm(){
                     //declare variables.
                     var objForm;
                     var objFullNameTextBox;
                     var objMessageBox;
                     var objAddress;
                     var objEmail;
                     var blnIsAllOkay = true;
                     var strName;
                     var strMessage = '';
                     var strEmail;
                     var strAddress;
                     var trimRE = /\s/;
    
                    objMessageBox = document.getElementById("divMessage");
                    objForm = document.getElementById("frmData");
                    objFullNameTextBox = document.getElementById("FullName");
                    objAddress = document.getElementById("Address");
                    objEmail = document.getElementById("Email");
    
                    strName = objFullNameTextBox.value;
                    strEmail = objEmail.value;
                    strAddress = objAddress.value;
    
    
                    strEmail = trimData(strEmail);
                    strAddress = trimData(strAddress);
    
                    strName = objFullNameTextBox.value;
                    strName = trimData(strName);
                    if (strName=="" ){
                        strMessage += "Please indicate Name<br>";
                        blnIsAllOkay = false;
                    }
                    if (strAddress=="" ){
                        strMessage += "Please indicate Address<br>";
                        blnIsAllOkay = false;
                    }
                    if (strEmail=="" ){
                        strMessage += "Please indicate Email<br>";
                        blnIsAllOkay = false;
                    }
    
                    function trimData(pstrData){
                        var intIndex=0;
                        var intRightIndex= pstrData.length -1;
                        while(intIndex < pstrData.length && trimRE.test(pstrData.charAt(intIndex)))
                        {++intIndex; }
                        while(intRightIndex > intIndex && trimRE.test(pstrData.charAt(intRightIndex)))
                        {--intRightIndex;}
                        return pstrData.substring(intIndex, intRightIndex+1);
                    }
    
                    if (strMessage.length){
                        objMessageBox.innerHTML = strMessage;
                    }
                    return blnIsAllOkay;
    
                }
                function clearErr() {
                    var objMessageBox = document.getElementById("divMessage");
                    objMessageBox.innerHTML = "";
                }
            </script>
        </head>
        <body>
            <div id="wrapper">
                <div id="header">
    
    <form id="frmData" name="frmData" action="process" method="post" onsubmit="return checkForm();">
    <table>
                    <tr>
                        <td>Full Name</td>
                        <td><input type="text" id="FullName" name="FullName" value=""></td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td><input type="text" id="Address" name="Address" value=""></td>
                    </tr>
    <tr>
                        <td>Email</td>
                        <td><input type="text" id="Email" name="Email" value=""></td>
                    </tr>
    
    
     <td>
                    <input type="submit" id="btnSubmit" value="Submit"/>
                    <input id="reset" type="reset" value="Reset" onclick="clearErr();"/></td>
            </tr></table>
            <div id="divMessage"></div>
        </form>
    But it only checks to see if the fields are empty or not. I've seen jQuery validation (the one I linked to in my last post) and it can be much more robust than just that by checking the format of responses to see if they contain expected characters, expected number of characters, spaces and/or numbers in certain places, etc. So could this script, with more tweaking.
    Last edited by jscheuer1; 08-13-2013 at 02:38 PM. Reason: add detail
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Form Wizard add button to submit the form
    By Foundas in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-11-2012, 08:55 PM
  2. ASP - form to form submit (cookies?)
    By deltatango5 in forum ASP
    Replies: 1
    Last Post: 09-23-2008, 11:51 AM
  3. submit form with javascript like a form does
    By ahs10 in forum JavaScript
    Replies: 2
    Last Post: 09-02-2008, 07:30 PM
  4. Form action Mailto need to open new page on submit and submit email
    By lstammer in forum Looking for such a script or service
    Replies: 0
    Last Post: 12-06-2007, 05:41 PM
  5. Replies: 1
    Last Post: 04-16-2006, 05:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •