www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: help with code

  1. #16
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,654
    the html is better ))

    as for javascript... my english is not good. it seems i used wrong word when wrote about "pair". i think it would be much better if somebody explain everything to you in right good english

    anyway, here is the code which works:

    Code:
    <!DOCTYPE html>
    <html>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/>
    <title>enter you number</title>
    <script type="text/javascript">
    function formValidator(){
    var max = 99;
    var min = 1;
    var val = parseInt(document.forms['myform'].elements['firstname'].value);
    var res = document.getElementById('result');
    if((val <= min) || (val >= max)){res.innerHTML = "Wrong number!";}
    else{res.innerHTML = "The number is between 1 and 99";}
    }
    </script>
    </head>
    <body>
    <center>
    <hr />
    <h1>enter your number</h1>
    <hr />
    <p>Note: all fields are mandatory.</p>
    <form name="myform">
    enter number between 1-99999: <input type="text" name="firstname" />
    <br /><br />
    <input type="button" value="Check it up" onclick="formValidator()" />
    <br /><br />
    <div id="result"></div>
    </form> 
    </center>
    </body>
    </html>
    Last edited by Padonak; 04-26-2012 at 04:39 PM.

  2. #17
    Join Date
    Apr 2012
    Posts
    13
    why wont this work?

    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/>
    <title>enter you number</title>
    <script type='text/javascript'>

    function formValidator(){

    var RunnerID = document.getElementById('RunnerID');
    var EventID = document.getElementById('EventID');
    var top = 99999
    var bottom = 1
    }
    }

    var boxValue;

    boxValue = parseFloat(textBox.value);
    if ( isNaN(boxValue) || (boxValue % 1 != 0) ||
    (boxValue < bottom) ||
    (boxValue > top)) {
    alert("You must enter an integer value in the range [" +
    bottom + ".." + top + "]");







    </script>
    </head>
    <body>
    <hr/>
    <h1>enter your number</h1>
    <hr/>
    Note: all fields are mandatory.
    <p/>
    <form>
    enter number between 1-99999: <input type="text" name="firstname"/><br />

    </form>
    </body>
    </html>

  3. #18
    Join Date
    Apr 2012
    Posts
    13
    Quote Originally Posted by stevenn21 View Post
    why wont this work?

    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    <meta http-equiv="Content-type" content="text/html; charset=iso-8859-1"/>
    <title>enter you number</title>
    <script type='text/javascript'>

    function formValidator(){

    var RunnerID = document.getElementById('RunnerID');
    var EventID = document.getElementById('EventID');
    var top = 99999
    var bottom = 1
    }
    }

    var boxValue;

    boxValue = parseFloat(textBox.value);
    if ( isNaN(boxValue) || (boxValue % 1 != 0) ||
    (boxValue < bottom) ||
    (boxValue > top)) {
    alert("You must enter an integer value in the range [" +
    bottom + ".." + top + "]");







    </script>
    </head>
    <body>
    <hr/>
    <h1>enter your number</h1>
    <hr/>
    Note: all fields are mandatory.
    <p/>
    <form>
    enter number between 1-99999: <input type="text" name="firstname"/><br />

    </form>
    </body>
    </html>
    ok this is my entire program anyone know why it wont validate?

  4. #19
    Join Date
    Jan 2011
    Posts
    123
    1. why do you tell the browser that your document is xhtml when you are writing html?
    2. where did you learn that dom manipulating scripts are to be put on the document head if at all?
    3. why do you call for var RunnerID = document.getElementById('RunnerID'); when there's no RunnerID element anywhere in your document except in your imagination?
    4. the same question for: var EventID = document.getElementById('EventID');- what EventId? Where is it?
    5. Why are you closing the "}" you didn't open?
    6. Why do you open brackets ({) you don't want to close ?
    7. parseFloat(textBox.value); -what textBox value, where textBox.value?! are you seing things?
    8. if ( isNaN(boxValue) ; what if isNaN for boxValue? -there is no boxValue!

    The reason I'm replying to you was not to answer your question, even though I already answered it, - but to ask you, where on earth did you get the guts to ask 'why wont >>this<< work' ?!

  5. #20
    Join Date
    Apr 2012
    Posts
    13

    Smile

    Quote Originally Posted by Troy III View Post
    1. why do you tell the browser that your document is xhtml when you are writing html?
    2. where did you learn that dom manipulating scripts are to be put on the document head if at all?
    3. why do you call for var RunnerID = document.getElementById('RunnerID'); when there's no RunnerID element anywhere in your document except in your imagination?
    4. the same question for: var EventID = document.getElementById('EventID');- what EventId? Where is it?
    5. Why are you closing the "}" you didn't open?
    6. Why do you open brackets ({) you don't want to close ?
    7. parseFloat(textBox.value); -what textBox value, where textBox.value?! are you seing things?
    8. if ( isNaN(boxValue) ; what if isNaN for boxValue? -there is no boxValue!

    The reason I'm replying to you was not to answer your question, even though I already answered it, - but to ask you, where on earth did you get the guts to ask 'why wont >>this<< work' ?!
    hi troy iii this is not my code i have only been using javascript for 2 days a friend asked for my help most of the code you see is his code and the rest is what i pasted in from the internet as i have no knowledge of javascript i didnt know how to adapt it to fit in the code. i had problems with the runnerID and didnt know why now i know because you have told me, Padonak helped put the code right and thanks to him it works now.
    thank you for your help and constructive critism troyiii its how we learn

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles