Results 1 to 10 of 10

Thread: Im just learning Javascript and..

  1. #1
    Join Date
    May 2010

    Im just learning Javascript and..

    I'm reading through javascript demystified and am currently in chapter 7, Forms and Event Handling. Example 7-1 shows the following code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml>
    <title>onblur event</title>
    <script language="Javascript" type="text/javascript">
    function ValidateEmail(emailaddy)
    var loc=emailaddy.indexOf('@')
    if(loc == -1)
    alert('you entered an inaccurate email addy.')
    <FORM action="http://www.jimkeogh.com" method="post">
    First Name: <INPUT type="text" name="Fname"/><BR>
    Last Name: <INPUT type="text" name="Lname"/><BR>
    Email: <INPUT type="text" name="Email" onblur="ValidateEmail (this.value)"/><BR>
    <INPUT name="Submit" value="Submit" type="submit"/>
    <INPUT name="Reset" value="Reset" type="reset"/>

    When I try to load it in a browser, the form loads fine but the browser isn't displaying an alert box. So I don't even know if it is calling the function correctly. Could someone look over this and explain whats going on or what I've done wrong?

  2. #2
    Join Date
    Mar 2010
    All that is needed is some basic Debugging 101

    The Firefox error console tells you what the error is and the line number its in.

    You have an obvious syntax error.

  3. #3
    Join Date
    May 2010
    It is saying the error is in line 1, and is pointing out ValidateEmail portion of the function, saying it is not defined. see below pic. I'm not sure why it's not defined and could you please point out what I need to do here?


  4. #4
    Join Date
    May 2010
    well I don't know how I got it working, all I did was removed the junk in the html tag and the doctype line. So... I'm lost on that part but it is working fine now.

  5. #5
    Join Date
    May 2010
    Please use the html and the code tags, also put better topic titles, that really describe what's you're question.

    Keep the forums clean and organized.
    "Scripting is the future of the development languages" --Nathan Paulino Campos(me)

  6. #6
    Join Date
    Apr 2010
    Hi techdead,

    The script you provided works fine.

    You seem to be confused on what an onblur event is.

    A user clicks on the form field, and it focuses on that field. This is called onfocus.

    The user then clicks out of the form field, and it is not longer focused. This is called onblur.

    So, enter an email address into the form field, and then click out of the field. Your alert box should appear.

  7. #7
    Join Date
    May 2010
    To ziggyism, I'm glad the code I provided is working correctly for you... it's nice to know that it is working properly. I'm quite clear on what the onblur and all the other tags that you can use like it do, what I was really concerned about was the fact that the browser would not execute that code correctly, tho it was copied verbatim from the book. I'm having similar issues with a couple of other examples on into chap 7 of the book.

    And to nathanpc, the topic title was to get people to look at the forum post quickly , know that im new, and once you read the question contained in my first forum post then you know exactly what I was asking (tho sorry if it wasn't up to par for you). And i never said i got rid of the html and code tags i said i got rid of the junk in them... aka the parts that were completely unnecessary.

  8. #8
    Join Date
    Mar 2010
    Quote Originally Posted by techdead View Post
    well I don't know how I got it working, all I did was removed the junk in the html tag and the doctype line. So... I'm lost on that part but it is working fine now.
    By removing the extra text in the <html> you removed the source of the error - missing closing "

    In your original post:

    <html xmlns="http://www.w3.org/1999/xhtml>
    should have been

    <html xmlns="http://www.w3.org/1999/xhtml">

  9. #9
    Join Date
    May 2010
    Aha! Thank you Tirna! I knew it would be something like that... I had been so annoyed over that.

  10. #10
    Join Date
    Mar 2010
    no problem - glad you sorted it out.

    .....tho it was copied verbatim from the book. I'm having similar issues with a couple of other examples on into chap 7 of the book.....
    Imo code in text or any books should not be blindly taken as 100&#37; correct. There is always a possibility if typos or misprints - albeit these are rare.

    Depending on the problem, sources of errors in problematic html code can be found by putting the hml code through the w3c validator at:


    anyway, just some food for thought

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.10847 seconds
  • Memory Usage 2,942KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates