Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    348
    Thanks
    39
    Thanked 0 Times in 0 Posts

    Javascript codes in Jquery do not work directly

    So, I have a page which is made by JQuery mobile and there are also some JavaScript codes for input validation included. The problem is, the JavaScript codes are not in action each time the page is opened. However, they work ONLY if I refresh the page again.

    It is an app which I am developing using Phonegap.Anyway, here are my codes:

    Full page HTML codes

    Code:
    <html>
    <head>
    <title>Poem</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <link href="jquery/jquery.mobile-1.4.2.css" rel="stylesheet" type="text/css"/>
    <script src="jquery/jquery.js" type="text/javascript"></script>
    <script src="jquery/jquery.mobile-1.4.2.js" type="text/javascript"></script>
    </head>
    
    <body>
    <div data-role="page" >
    <div data-role="header">
    <h1>Poem</h1>
    </div>
    <p>Your name</p>
    <input type="text"  id="namesur" />
    <input type="button" onClick="validate()" data-role="button" value="Send" /></p>
    <p id="message"></p>
    </div>
    </body>
    </html>

    The JavaScript codes to validate the textbox if empty


    PHP Code:
    <script>
    function 
    validate() {
    var 
    nam document.getElementById("namesur").value;
    if (
    nam === "")  {
     
    document.getElementById("message").innerHTML "Please fill the field";

    </script> 
    I badly need to fix this. I do not know why it does not work each time I go on the page. On a desktop browser, you have to refresh the page for it work.

    Thank!

  • #2
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    349
    Thanks
    9
    Thanked 51 Times in 50 Posts
    Check again your Web Console (Ctrl-Shift-K in Firefox).
    I think your script just missed one closing curly bracket.


  •  

    Tags for this Thread

    Posting Permissions

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