• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

change from input tag to button

 
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following form which works fine:




I want to do some things inside a createCompany() function and if something is true, then only go ahead with the form submission. So I have tried changing it to a button tag linke this:



and after uncommenting the createCompany() function, I can see the form is submitted but I do see an error in console "Uncaught TypeError: this.form is undefined"

Am i doing anything wrong above?
 
Sheriff
Posts: 67752
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
What are you expecting this to be evaluating to? (Hint: probably not what you think.)

The likely quickest path to find the input element you want to change is to assign an id and use document.getElementById.

You also probably don't want to do this in a click handler, but rather in a handler for the form's submit event.
 
Jack Tauson
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:What are you expecting this to be evaluating to? (Hint: probably not what you think.)

The likely quickest path to find the input element you want to change is to assign an id and use document.getElementById.

You also probably don't want to do this in a click handler, but rather in a handler for the form's submit event.



Could you maybe explain by providing a code example? Thanks!
 
Saloon Keeper
Posts: 28325
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not just a JSP thing, but the best way to validate data client-side before submitting isn't to use onclick(), it's to use onsubmit(). The code that onsubmit executes returns true or false depending on whether you want the submit to proceed or be aborted.
 
Jack Tauson
Ranch Hand
Posts: 458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:This is not just a JSP thing, but the best way to validate data client-side before submitting isn't to use onclick(), it's to use onsubmit(). The code that onsubmit executes returns true or false depending on whether you want the submit to proceed or be aborted.




I believe you are referring to using onsubmit() like this ?

 
Tim Holloway
Saloon Keeper
Posts: 28325
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In form, yes. Of course, the action's actual value should be something like "${context}/userCreate", and I prefer to add a final ";" on the JavaScript for consistency's sake (it's not required, of course). I used "${context}" as a stand-in for the full URL path (relative URLs can bite you). Don't remember the exact method for JSPs at the moment. Straight HTML can use the docbase tag to help.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic