• 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

JavaScript Form Validation Issue

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

My code is as follows




The reason I am using input tag with type as hidden because I need to know which button was hit so that I can insert or update accordingly and send the error across (if generated).


When I click any of the buttons (i.e. either Save or Update) with no data on any of the text boxes.

1. It hits the server without actually getting itself validated first. I did put a dummy alert() inside the script to check the same.

When I use form attribute onsubmit="return validate(this);" and remove the onclick attributes of both the buttons,

1. It validates the form but continues to hit the server when false is returned. I can't use this form onsubmit event since I am loosing hidden attribute's value.

Modified code as follows:-



I don't know where is the issue.


Please Help !!!.



I hope you guys will forgive me for visiting the site after a very long time.


 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


returns an array and you are treating it like a single dom element with evt.foo.value

It is better to give your form an id and use getElementById, that will return a single DOM element.

also why evt? most developers that would mean event.

Eric
 
Anshuman Chakraborty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Eric,

This was the issue.

I also updated the variable name as rightly pointed out.


Thank you very much.

reply
    Bookmark Topic Watch Topic
  • New Topic