Results 1 to 8 of 8
  1. #1
    kritijain is offline Member
    Join Date
    Jun 2011
    Posts
    6
    Rep Power
    0

    Default validurl function not working when I click the submit button

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
    <title> Url Shortner</title>
    </head>
    <SCRIPT LANGUAGE="javascript">
    function validurl()
    (
    {
    alert("inside valid_url");
    var myfield= document.getElementById("lurl");
    {
    if(myfield.value == "")
    alert("ERROR: Please enter some url");
    return false;
    }
    return true;
    }
    }
    </SCRIPT>
    <body>

    <center>

    <% String cPath= request.getContextPath()+"/images/";
    %>
    <table border ="0" align="left" width="100%">
    <tr>
    <td colspan="2" align="center"><b>URL SHORTNER</b>
    </td>
    </tr>

    <tr>
    <td colspan="2" align="left">
    <img src="<%=cPath%>redLine.jpg" border="0" height="2" width="100%">
    </td>
    </tr>

    <tr>
    <td colspan="2" align="center"><b>Paste Long URL here: &nbsp;</b>
    </td>
    </tr>

    <tr>
    <td align="center">
    <input type="text" value="" size="60" name="lurl" id="lurl">
    </td>
    </tr>


    <tr>
    <td colspan="2" align="center"><br>
    <b>Description:&nbsp;</b>
    </td>
    </tr>

    <tr>
    <td align="center">
    <textarea name="description" rows="5" cols="50"></textarea>
    </td>
    </tr>

    <tr>
    <td colspan="2" align="center">
    <br>
    <input type="submit" value="" name="submit" onkeypress ="javascript:validurl();"
    style="background:url(<%=cPath%>btn_submit.gif); width:75px; height:25px;" >

    </td>
    </tr>

    <tr>
    <td colspan="2" align="center">
    <br>
    <b>Short url is : http://goo.gl..........</b>
    </td>
    </tr>


    </table>
    </center>
    </body>
    </html>

    this is the code i have written.
    but in this code the submit button is not working. When I click the submit button the validurl function should work but it is not.
    plz solve my prblm.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Please use code tags when posting code:
    Java Code:
    function validurl()
    (  [B]// What's this bracket doing here?[/B]
    {
        alert("inside valid_url");
        var myfield= document.getElementById("lurl");
        {
            if(myfield.value == "")  [B]// Should this have curly braces?[/B]
                alert("ERROR: Please enter some url");  [B]// This is the only line the above if controls.[/B]
            return false;  [B]// Because your if has no brackets, this method will always return false.[/B]
        }
        return true;
    }
    }  [B]// What's this left over bracket?[/B]

  3. #3
    kritijain is offline Member
    Join Date
    Jun 2011
    Posts
    6
    Rep Power
    0

    Default

    i have removed the brackets also but still it is not running.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    What about your if statement?

    Also "It's not working" doesn't actually tell us anything.

  5. #5
    kritijain is offline Member
    Join Date
    Jun 2011
    Posts
    6
    Rep Power
    0

    Default

    function validate()
    (
    var myfield = document.getElementById("lurl");
    var name = myfield.value;
    if(name == "")
    {
    alert("ERROR: Please enter some url");
    return false;
    }
    return true;
    }
    this is the code m trying to run.
    but it is not working. :)

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    And?
    What does "not working" mean?
    Note, I have no idea of what your requirements are and I also have no intention of attempting to set up something to actually run this.

    Have you treid debugging it? Ther's reasonable Javascript debuggers available for all the main browsers.

    ETA: And use code tags!

  7. #7
    kritijain is offline Member
    Join Date
    Jun 2011
    Posts
    6
    Rep Power
    0

    Default

    i jst want to add the funcionality to a buton.

    i have created a button:
    <input type="submit" value="" name="submit" onkeypress ="javascript:validate();"
    style="background:url(<%=cPath%>btn_submit.gif); width:75px; height:25px;" >

    n want if a user clicks this button then the validate function should call whch is this:

    function validate()
    (
    var myfield = document.getElementById("lurl");
    var name = myfield.value;
    if(name == "")
    {
    alert("ERROR: Please enter some url");
    return false;
    }
    return true;
    }

    but this code is not working and not showing any error or warning too.
    m using eclipse ganymede and running on tomcat server.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    This is Javascript.
    It has nothing to do with eclipse or tomcat.
    It runs on the client.
    To be honest, it's not something we deal with in this forum except with regards to things like Ajax, which this isn't.

    Add additional alerts in there to see what's going on, if you;re unable to debug it yourself. But a debugger would be better.

    And use code tags!

Similar Threads

  1. Please help : JSP ,Submit button and servlet
    By kalyana in forum JavaServer Pages (JSP) and JSTL
    Replies: 12
    Last Post: 03-30-2011, 07:32 AM
  2. Submit, button, focus
    By Aschee in forum New To Java
    Replies: 0
    Last Post: 03-28-2011, 05:31 PM
  3. JSP program to handle submit button
    By gurpreet.singh in forum JavaServer Pages (JSP) and JSTL
    Replies: 6
    Last Post: 03-09-2011, 06:46 AM
  4. run actions, submit form and close on click
    By marckamga in forum Java Servlet
    Replies: 3
    Last Post: 09-29-2010, 12:21 PM
  5. Submit Button Help
    By Jay-1.1 in forum New To Java
    Replies: 2
    Last Post: 05-06-2008, 05:28 PM

Posting Permissions

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