• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use two different submit buttons, for two different actions, on one page?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've looked this up before, on StackOverflow, and did exactly as it said -- as far as I can tell. I'm stuck with an "uncaught reference error - action not defined" at line 17, "if (action == "Submit") {" which is driving me nuts. Fiddle is here:

http://jsfiddle.net/7f47mazk/1/

or you can just look at the terrible thing, it's all in the source code on that one page:

http://hills.ccsf.edu/~dnuccite/cnit133/hw5d.html

The goal is that the user will be able to enter the number of employees, hit submit, and automatically generate a form on the same page that has that very same number of input fields.

Probably someone saner and wiser than I will look at it and say "Oh, you left out a curly bracket right here," but I am at the end my rope with it. Any words of wisdom for this newbie would be greatly appreciated.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

If I enter a number and click Submit, I get a "action is not defined" error. You can see errors in Firefox by opening the Console: Tools -> Web Developer -> Browser Console. Taking a quick look at the page source, no "action" variable seems to be defined.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might have intended to use forms[0].action . It is clear that no such variable as action is defined. We usually use forms[0]. action or make use of a reference to the named form. Hope this helps
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any reason you're not using jQuery to simplify everything?

 
Dani Stone
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Any reason you're not using jQuery to simplify everything?



Yup -- because I don't know how! Any suggestions would be welcome.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are going to be writing this level of JavaScript you should learn jQuery asap. It makes everything much easier and cross-browser.

But specifically in your code, I see nowhere where action is defined prior to being used. Not to mention that you are running code as the unload handler that executes before any button can even be pressed.

You should also always have the JavaScript console open when developing. It will show you any JavaScript errors.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic