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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Return message if first value is correct?

    Hi, I'm trying to figure out how to make this work and I'm stumped.

    I wrote this code:


    <script type=text/javascript>
    function firstfunction();
    {
    if(document.form1.inputnumbers.value="55");
    {
    document.form1.outputstate.value="this is a number";
    }
    else if
    {
    document.form1.inputnumbers.value="never";
    }
    {
    document.form1.outputstate.value="this is a number";
    }
    else
    {
    document.form1.outputstate.value="";
    }
    </script>


    <form name="form1" method="post">
    <input type="text" id="inputnumbers" name="inputnumbers";>
    <input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
    <textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;>


    I'm trying to doing something really simple but I can't seem to make it work. I'm trying have the textarea display a certain message depending on if the first input box says a certain word or number. So like in the code, if the user types "55" or "never" in the first box, then the second box should say a certain message. Then I used the else statement so that if "55" or "never" is not entered, then the second box says nothing.

    If you can spot my error or suggest a different way of going about writing the code, it would be very much appreciated. Thank you.

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That's like a picture of every elementary error possible, I think.

    Look at these (among others):
    Code:
    <script type=text/javascript>
    function firstfunction();
    {
    if(document.form1.inputnumbers.value="55");
    {
    document.form1.outputstate.value="this is a number";
    }
    else if
    {
    document.form1.inputnumbers.value="never";
    }
    {
    document.form1.outputstate.value="this is a number";
    }
    else
    {
    document.form1.outputstate.value="";
    }
    //missing closing function brace
    </script>
    Are you a Help Vampire?

  • #3
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi, thanks for your help finding the errors. yes, I know I make lots of mistakes I am still learning. I corrected the errors in red, and tried several new ways of rewriting the code but it still isn't working.

  • #4
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Show the corrected code.

    By the way, your browser should be dumping notices for syntax errors like above.
    Are you a Help Vampire?

  • #5
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    This is the corrected code:


    <script type=text/javascript>
    function firstfunction()
    {
    if(document.form1.inputnumbers.value == "55")
    {
    document.form1.outputstate.value="this is a number";
    }
    else if(document.form1.inputnumbers.value="never")
    {
    document.form1.outputstate.value="this is a number";
    }
    else
    {
    document.form1.outputstate.value="";
    }
    }
    </script>

    <form name="form1" method="post">
    <input type="text" id="inputnumbers" name="inputnumbers";>
    <input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
    <textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;>



    It does something, just not what I want it to do.
    I'm using http://htmledit.squarefree.com/ to edit the code, so it's not showing any syntax errors for me.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,985
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Code:
    <script type=text/javascript>
    function firstfunction() {
    if(document.form1.inputnumbers.value == "55") {
    document.form1.outputstate.value="this is a number";
    }
    else if(document.form1.inputnumbers.value == "never"){
    document.form1.outputstate.value="this is a number";
    }
    else {
    document.form1.outputstate.value="";
    }
    } 
    </script>
    
    <form name="form1" method="post">
    <input type="text" id="inputnumbers" name="inputnumbers";>
    <input type="button"; value="Enter"; onclick="firstfunction()"><br><br>
    <textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;> </textarea> 
    </form>
    Note that "Never" or "NEVER" != "never".

  • Users who have thanked Philip M for this post:

    jeanrigole (06-21-2010)

  • #7
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much for the help, I almost had it, I just overlooked simple errors. thank again


  •  

    Posting Permissions

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