Home > Articles > Open Source > Ajax & JavaScript

  • Print
  • + Share This
This chapter is from the book


  1. If I use JavaScript to add validation and other features to my form, can users with non-JavaScript browsers still use the form?

  1. Yes, if you're careful. Be sure to use a Submit button rather than the submit action. Also, the CGI script may receive nonvalidated data, so be sure to include validation in the CGI script. Non-JavaScript users will be able to use the form, but won't receive instant feedback about their errors.

  1. Can I add new form elements "on the fly" or change them—for example, change a text box into a password field?

  1. No. The form elements are set by the HTML code. There are ways to work around this, such as updating the form in a separate frame or layer.

  1. Is there any way to create a large number of text fields without dealing with different names for all of them?

  1. Yes. If you use the same name for several elements in the form, their objects will form an array. For example, if you defined 20 text fields with the name member, you could refer to them as member[0] through member[19]. This also works with other types of form elements.

  1. Why doesn't JavaScript recognize my form elements when I use a table to lay them out?

  1. Some versions of JavaScript do not deal well with forms or scripts within tables when <table> tags are nested. For now, the only solution is to avoid using nested tables.

  1. Is there a way to place the cursor on a particular field when the form is loaded, or after my validation routine displays an error message?

  1. Yes. You can use the field's focus() method to send the cursor there. To do this when the page loads, you can use the onLoad method in the <body> tag. However, there is no way to place the cursor in a particular position within the field.

  • + Share This
  • 🔖 Save To Your Account