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 8 of 8
  1. #1
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts

    why won't this work? - document.test.area.value -

    Hello everyone,l was hoping someone could tell me why either of the following functions do not work:

    Code:
    <script>
    function test(){
    alert(document.break.time.value);
    }
    </script>
    
    
    <script>
    function test2(){
    c = document.break.time.value;
    alert(c);
    }
    </script>
    
    <form name="break">
    <input name="time" type="text" size="5" value="0">
    </form>
    
    <br><br>
    <a href="javascript:test()">TEST1</a>
    <br>
    <a href="javascript:test2()">TEST2</a>
    This is something that happens to me *all the time* and l can't figure it out.. l just end up re-writing the script until it works.. but l honestly can't figure out what the problem is.. can anyone help me please?

    Thanks

    Samantha Gram.

  • #2
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Now here's something that really trips me out -- l just changed

    the form name to "b" (instead of "break");
    and the code seem'd to work...

    however if l change the form name to "brk" and the input name to "tm" it doesn't work...

    as in:

    Code:
    
    
    <script>
    
    function break_time(){
    
    alert(document.brk.tm.value);
    
    }
    break_time();
    </script>
    
    
    <form name="brk">
    <input name="tm" type="text" size="5" value="0">
    </form>
    Samantha Gram.
    Last edited by Coastal Web; 03-25-2005 at 08:42 PM.

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    mile high city
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As you've seen, break is a reserved word...

    http://javascript.about.com/library/blreserved.htm
    Computer, kill Flanders... Did I hear my name? My ears are burning...
    Good start. Now finish the job.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    The way you have this set out


    PHP Code:
    <script>

    function 
    break_time(){

    alert(document.brk.tm.value);

    }
    break_time();
    </script>


    <form name="brk">
    <input name="tm" type="text" size="5" value="0">
    </form> 
    the script runs before the form has loaded and will produce an error

    You should use onload=break_time in the script or move break_time() to the opening body tag.

    <BODY onload="break_time()">
    Last edited by Mr J; 03-26-2005 at 03:07 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #6
    Regular Coder Coastal Web's Avatar
    Join Date
    Oct 2004
    Posts
    225
    Thanks
    12
    Thanked 3 Times in 3 Posts
    Thank you Mr J for your help!!


    As the other two people had replied (thank you as well) however if you would have read my posts you'd have seen that using a reserved word wasn't my problem - as l'd change the "break" to "b" for the name of the form element..

    2ndly - l wasn't using a reserved word to name a variable... But thanks for trying as they say lol.

    Samantha Gram.

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Samantha Gram
    Last edited by Samantha Gram : 03-25-2005 at 07:42 PM.
    (this reflects my timezone, yours may vary)
    And if you return and read your post again you will find that you returned and editted your post AFTER myself and mcdougals4all had replied... So thank yourself for any confusion and/or misunderstanding...

    .....Willy

  • #8
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    BTW: In the event you misunderstood my previous post...

    Let me try to explain it again...
    Just because you return and edit your post and change the goal line so to speak...
    Do not expect us to return and edit our posts to answer your additional questions...

    Good thing the forum software adds the editted notice or you would have us looking like idiots by changing your post after we responded to your original post...
    .....Willy


  •  

    Posting Permissions

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