www.webdeveloper.com
Results 1 to 12 of 12

Thread: [RESOLVED] simple function help

  1. #1
    Join Date
    Apr 2012
    Posts
    110

    resolved [RESOLVED] simple function help

    I am trying to check the value of a text field when the user types something in. here is what i have:

    for the text field:
    Code:
    onkeypress="alertMe();"
    and the jQuery:
    Code:
    function alertMe(){
    		alert('ok');
    	}
    it does not seem to do anything. i even tried adding "javascript:" for the onkeypress.

  2. #2
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Here is your answer and more...

    http://jsfiddle.net/MZDbX/7/


    Please click under "Thread Tools" and mark this question as [RESOLVED].
    Last edited by donatello; 08-03-2012 at 04:38 AM. Reason: Resolved reminder...

  3. #3
    Join Date
    Apr 2012
    Posts
    110
    here is my code: http://jsfiddle.net/LRKbz/
    i looked at yours, and tried to make it similar, but don't see what i'm missing.

  4. #4
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Yours was fine, you just had to set the framework for something other than 'onload' (in the left hand column.)

    Then your script works fine.

    http://jsfiddle.net/LRKbz/2/


    Look to the left where it says "Choose Framework".
    You had it set to 'onload'.
    All I did was change it from "Onload" to "no wrap body".
    Works fine!

  5. #5
    Join Date
    Apr 2012
    Posts
    110
    weird... i did this, and it still doesn't work.... any other ideas as to why?

  6. #6
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Try it in your browser... sometimes the JS fiddle is quirky...

    W/regard to JSFiddle.net...
    Of course, when you make changes, you have to click 'run' again.

    Don't be afraid to use the "Tidy Up" button and the "Fork" and/or "Update" button.

  7. #7
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    What browser are you using?

    My examples are working fine in my browser... are you seeing them work?

  8. #8
    Join Date
    Apr 2012
    Posts
    110
    i'm thinking its still with my code because i've tried two different browsers. what i am trying to do is create a part of a registration page where the user has to enter their information. after the user either a) fills out all the forms properly b) submits the form, and all forms are good... then there is a green check mark which means ok. otherwise, there is an exclamation mark saying that there is something wrong with this section. in regards to this post, i thought it would be a good idea to possibly validate as i go? another alternative would be to have the user submit, then validate. any ideas?

  9. #9
    Join Date
    Apr 2012
    Posts
    110
    i found what the error was now:
    i had the function, alertMe inside of the $(function() { tag. i put it before it, and now it works. why can't i have it inside of this tag?

  10. #10
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114

  11. #11
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114
    Quote Originally Posted by droidus View Post
    i found what the error was now:
    i had the function, alertMe inside of the $(function() { tag. i put it before it, and now it works. why can't i have it inside of this tag?
    I'm not sure, there are far better JS programmers around here than me, I am a novice...

    I get lucky sometimes and stuff I mess with works. Sometimes it does not and I'm clueless as to why!

    ...one of these days...

    Good luck with your site!

  12. #12
    Join Date
    Apr 2012
    Posts
    110
    no problem - thanks for your help!

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