Results 1 to 7 of 7

Thread: Why won't my code work?

  1. #1
    Join Date
    Jul 2011
    Lost in space

    Why won't my code work?

    My code won't work! How do I combine action agruments? Can you please help?
    HTML Code:
    <script type="text/javascript">
    function confirmInput()
    alert("Hello, " + fname + "! You will now be redirected to the Monkeypuzzle Manor Home Page.");
    <script type="text/javascript">
    function validateForm()
    var x=document.forms["myForm"]["question"].value
    if (x==null || x=="")
      alert("Please write a message in the message field");
      return false;
    <script type="text/javascript">
    function validateForm()
    var x=document.forms["myForm"]["email"].value
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
      alert("The e-mail address you submitted is not valid. Please enter a valid e-mail address.");
      return false;
    <form name="myForm" method="post" action="mailto:MYEMAIL" action="http://babybear.us/" enctype="text/plain" onsubmit="confirmInput()" onsubmit="return validateForm()">
    <table style="border:0px">
    <td>Name: </td><td><input id="fname" name="fname" type="text" size="20"></td></tr>
    <td>E-mail: </td><td><input type="text" name="email" size="30"></td></tr>
    <td>Question Type: </td><td><select name="questiontype" size="1"> <option>General question about Monkeypuzzle Manor</option><option>Question about item(s)</option><option>Feedback for Monkeypuzzle Manor</option><option>Feedback about item(s) received</option><option>Other question/comment type</option></select></td></tr>
    <td valign="top">Message: </td><td><textarea name="question" rows="10" columns="20"></textarea></td></tr>
    <td valign="top">Overall, how would you rate Monkeypuzzle Manor?</td>
    <td valign="top"><input type="radio" name="rating" value="excellent" />Excellent<br />
    <input type="radio" name="rating" value="good" />Good<br />
    <input type="radio" name="rating" value="fair" />Fair<br />
    <input type="radio" name="rating" value="poor" />Poor<br />
    <input type="radio" name="rating" value="verypoor" />Very Poor<br /><br /></td>
    <tr><td valign="top"></td><td><input type="checkbox" name="yes" checked="checked" /> Yes, I would like to receive e-mail updates of Monkeypuzzle Manor's available items.</td>
    <br />
    <input type="submit" value="Send Message"><input type="reset" value="Clear Fields">
    I'm using babybear.us (my other site) in lieu of Monkeypuzzle Manor's (my current project's) home page.
    Thanks in advance!

  2. #2
    Join Date
    May 2011

    clean your code to find (logically) errors


    clean your code and make it shorter. Check logically structure of functions. Use arguments for function
    to replace values or references of global vars. Don't uses values that function not need for action.
    Thrn you find errors easier.

    function validateForm()
    var x=document.forms["myForm"]["question"].value
    if (x==null || x=="")
    alert("Please write a message in the message field");
    return false;

    // and else ? no return ?

    you mean

    function validateForm(stValue) // replace document.forms["myForm"]["question"].value
    // function only compare value ... and so not need a reference.
    {return ( (stValue!=null) && (stValue!=""));}

    {alert(alert("Please write a message in the message field");}


    function confirmInput()
    alert("Hello, " + fname + "! You will now be redirected to the Monkeypuzzle Manor Home Page.");

    // alert do not confirm

    you mean

    function confirmInput(stMessage1,stValue,stMessage2) // arguments not null and not empty
    return (confirm(stMessage1 + stValue + stMessage2")); // true for OK button

    if(confirmInput("Hello, ", document.forms[0].fname.value,stMessage, "! Do you want now to be redirected to the Monkeypuzzle Manor Home Page ?")
    {alert("user want");}


    function validateForm()

    // same: no return inside else


    a function should have ONE return
    store return value into var

    function validateForm(stValue) // argument must be !=null and != ""
    // stValue ingoing of function, a reference like document.forms["myForm"]["email"].value not needed for compare of positions
    var atpos=stValue.indexOf("@");
    var dotpos=stValue.lastIndexOf(".");
    var boReturn=true; // for else and default

    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)

    return boReturn; // ONE return (outgoing of function)

    {alert("The e-mail address you submitted is not valid. Please enter a valid e-mail address.");}

  3. #3
    Join Date
    Jul 2011
    Lost in space
    sry i didn't quite get that...you see, I'm only just learning JS, this is my 2nd website ever and I'm trying to "pick up" JS the same way I picked up HTML...copy, paste, tinker, repeat. Hey, it works...I have most transitional HTML 4.01 committed to memory lol. Now I know more about that than my dad- and he's a systems admin lol.

  4. #4
    Join Date
    May 2011

    try that ....


    Webpage editors support tools and functions to build in.

    Like that .... copy and paste


    but it's not freeware.
    Try the trial. If good your dad should buy software with full support.

    Or see free editor http://www.coffeecup.com/free-editor/


    To test your code use browser like Opera.

    Browsers offers log windows for messages about error (kind of error, position).
    This informations you need ... for offers in forum too.

    No code ist perfect. Optimze your code after clean.

    If you not want use wysiwyg webbuilder what you see is what you get ...


    To create a webpage by hand you must learn content of HTML DOM.
    wysiwyg webbuilder use HTML DOM too, but offers prefedined functions
    like formular checker etc.

    For the way by hand take reference of Microsoft, see http://msdn.microsoft.com/en-us/library/ms533050.aspx

    All objects you use in your code you find in this reference.

    Try that way to find better arguments for your dad to buy wysiwyg webbuilder.
    Easy, quickly to get your webpage.

    Maybe, after some lessions in HTML by use wysiwyg webbuilder you want programming by hand.


    One of finest editors for HTML are Allaire Homesite and Macromedia Dreamwaver.

    Allaire is dead. My be you find an old version in use torrents network.

    Adobe.com hosts Dreamweaver. Complete solution CS too. Highes profession.

    Try that, but your dad must have enough money to buy it.

    Adobe CS 5 opens creative webdesing from html over images videos to mobil phones.
    Complete solutions.


    Ahm, maybe your internet provider offers tools to create a webpage.

  5. #5
    Join Date
    Mar 2007
    Your form has two action parameters specified and two onsubmit handlers. Also you have two functions called validateForm.
    One of each of the above only please.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  6. #6
    Join Date
    May 2011
    Yes, two handlers and two functions with same name !
    Strangely, I would advise exactly the opposite to twseitex (Sorry, no
    offence meant).

    When you are learning (and beyond that stage) you need to fully grasp
    what your code is doing and how it is constructed. Using IDE tools which
    magically conjure up blocks of (often inefficient and non-compliant) HTML
    and Javascript teaches you little or nothing.

    Start with a good editor and a browser window open. Nothing more.
    By a 'good editor', I mean something like BBEdit which highlights code in
    a colour scheme, but even something like Notepad (Windoze) or
    TextEdit (Mac) is better for your learning process than Dreamweaver or
    the like.

    Products like FrontPage, which promise "a website in seconds' or some
    such nonsense, are not going to be helpful to your learning experience.
    They are toys for children.

    Sometimes, when you re-invent the wheel, you end up with a better wheel.
    One-on-One Scripting Tuition/Mentoring

  7. #7
    Join Date
    Jul 2011
    Lost in space
    Thank you guys!
    Why, yes! I am made of AWESOME!

    Visit my Web site at http://babybear.us/!

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.16170 seconds
  • Memory Usage 2,930KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (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
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (7)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (7)postbit
  • (7)postbit_onlinestatus
  • (7)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