Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8521997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:59:02+00:00 2026-06-11T06:59:02+00:00

I have a form on whose validation function a line throws an uncaught exception,

  • 0

I have a form on whose validation function a line throws an uncaught exception, but instead of stopping the execution the browser submits the form

http://jsfiddle.net/yur4U/1/

 function validation(){
   var value = document.forms["myform"]['badInput'].value;//this line throws an exception
   return false;
 }​

<form name='myform' action ="" onsubmit="return validation()" method="POST">
    <input name='myInput' value="testing" type="text"/>
     <input value="submit" type="submit"/>
</form >

the code above provides one is a simple example , but i might be doing some calculations or conversions which might produce an Exception.
One way to handle this is to enclose it in try catch

function validation(){
   var ret =true;
   try{
       var value = document.forms["myform"]['badInput'].value;
       ......//some condition to make ret=false
   } catch(e){
       ret = false
   }
   return ret;
 }​

But I am searching for a better way to do this? I think browser should be handling this by default, is this mentioned anywhere in the spec about how a browser should behave if onsubmit function throws an Exception?

​

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:59:04+00:00Added an answer on June 11, 2026 at 6:59 am
    var value = document.forms["myform"]['badInput'].value;
    //this line throws an exception
    

    Because there is no “badInput” named element in your form. Although it is better to use form.elements["elementName"] or even better use a JS framework (like jQuery / dojo / etc.).

    If you still need this line, you could check with typeof:

    if (typeof document.forms["myform"].elements['badInput'] != "undefined")
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form whose front page loads up correctly, but whenever I try
I have a form whose action is set to itself. I want it this
I have a dynamic dojo form in which I have a dijit.form.Select whose selected
I have a form that contains dataGridView, whose coloumn are set to dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;
Let's say I have a form where users can search for people whose name
I have form where user submits field. Field can have letters, numbers, and punctuation.
no title that fits this bug but this how it goes, i have form
I have a form generator that uses (perl compatible) regexes for ther backend validation.
I'm using Spring 3 and JSR 303. I have a form backing object whose
I have a situation in ASP.NET MVC 2 where I have a form whose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.