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

    My First JavaScript

    OK .. Solved ... there was a typing mistake in the code

    Today is my first day to start learning JavaScript. When i try to run the following code (copy-paste from a book), the browser gives me an error. Can you please tell me what's wrong with the following code:


    <HTML>
    <HEAD>
    <SCRIPT LANGUAGE = "JavaScript">
    function upperMe(){
    document.converter.output.value = document.converter.input.value.toUpperCase()
    }
    </SCRIPT>
    </HEAD>

    <BODY>
    <FORM NAME = "converter">
    <INPUT TYPE = "text" NAME = "input" VALUE="sample" onChange="upperMe()">
    <INPUT TYPE = "text" NAME = "output" VALUE="sdf">
    </FORM>
    </BODY>
    </HTML>


    Thanks
    Ahmad
    Last edited by AhmadWaqas; 09-28-2011 at 09:24 PM.

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Location
    Sweden
    Posts
    154
    Thanks
    1
    Thanked 22 Times in 22 Posts
    Also consider using document.forms instead of just document
    It's clearer and more standard compliant.
    Code:
    document.forms.converter ... etc

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    <script language="javascript"> is long deprecated and obsolete. Use <script type = "text/javascript"> instead.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,931
    Thanks
    56
    Thanked 552 Times in 549 Posts
    I would also consider using onkeyup for this type of operation:
    <INPUT TYPE = "text" NAME = "input" VALUE="sample" onkeyup="upperMe()">

    onchange doesn't quite cut it for me, although I know it has its place...


  •  

    Posting Permissions

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