Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

Validate <form> with out action attribute
Started by dillyw82, Oct 30 2012 02:02 AM
javascript validate
11 replies to this topic
#1
Posted 30 October 2012 - 02:02 AM
Hi i i have a assignment where i validate all forms are correctly filled in by user when click submit but i cant work out how to do it with out setting the action attribute, i have tryed action with "" & "#" ?
#2
Posted 30 October 2012 - 02:13 AM
the form tag wants a method and action. try action="yourfilename" method="get" where "yourfilename" is the filename you actually named your file to.
oh, also, your javascript needs to be called in the onsubmit attribute of the form tag.
oh, also, your javascript needs to be called in the onsubmit attribute of the form tag.
I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.
#3
Posted 30 October 2012 - 02:48 AM
I think the <form> tag does not require the method or action attributes
method should default to get, the action would default to the current page (url).
Very often you want the method to be 'POST' though, the action depends on the design of the website. I personally like staying on the same URL, so when some server validation goes wrong, it easily goes back to the form-page. But this is not required at all.
As for the javascript validation, like Orjan said, you need the onsubmit attribute:
method should default to get, the action would default to the current page (url).
Very often you want the method to be 'POST' though, the action depends on the design of the website. I personally like staying on the same URL, so when some server validation goes wrong, it easily goes back to the form-page. But this is not required at all.
As for the javascript validation, like Orjan said, you need the onsubmit attribute:
<html> <head> <script type="text/javascript"> function validateForm(){ if(field1.isEmpty() ){ return false; } else if(field2.isEmpty() ) { return false; } //continue for all fields return true; //if it reaches this line, all fields are processed, return true to submit form. } </script> </head> <body> <form onsubmit="validateForm()"> [...] </form> </body> </html>Note: field.isEmpty() is pseudo code, such method does not exist by default.
#4
Posted 30 October 2012 - 12:30 PM
Hi thanks you both for your replys i have tryed both but still not getting the alert popping up would you mind taking a look at my file for me please
Attached Files
#5
Posted 30 October 2012 - 02:23 PM
First, let's get rid of the syntax errors
:
Then, why does it not do an alert?
Because your onsubmit method is called 'checkForm', but in the javascrpit it's called 'validate'.
So changing that should make things working.

Spoiler
Then, why does it not do an alert?
Because your onsubmit method is called 'checkForm', but in the javascrpit it's called 'validate'.
So changing that should make things working.
<form name="input" action="JoesFruit.html" method="get" onsubmit="validate()">
#6
Posted 30 October 2012 - 02:29 PM
oh golly gosh thanks cant believe i missed that, still not working though ?
and i corrected resturn to return still not working
and i corrected resturn to return still not working
#7
Posted 30 October 2012 - 02:29 PM
Are you sure you press the submit button with the name empty? Becuase if it's filled with 'Please fill your name', it won't be empty and you'll get no alert.
Which browser do you use mainly?
Which browser do you use mainly?
#8
Posted 30 October 2012 - 02:38 PM
i have corrected a few smelling mistakes and changed a few things but still not working i will put up the updated copy
yeah i have emptyed it
i use IE9
just tryed with firefox dont work there either
ok got it not thank you for your time, how did you do that check over the code that come up with the errors?
yeah i have emptyed it
i use IE9
just tryed with firefox dont work there either
ok got it not thank you for your time, how did you do that check over the code that come up with the errors?
Attached Files
#9
Posted 30 October 2012 - 02:45 PM
Okay, to help debugging Javascript open your file in IE.
Then press F12, a 'developers tools' window opens.
Now press refresh in the normal IE window.
After that go to the tools window, click on the script tab. And there on the right under 'console' it will list any Javascript error.
Should look like:

It states it's missing a '}' at line 36.
Line 36 is the end of the script part - So what that means is you didn't close a brace where you've opened one.
I've pointed that out as error in my previous post as
After you've edited the file, and refreshed the browsers you'll see that in the tools window it still shows the error. But that's the error from the previous run, so no worries.
You can avoid this by right clicking where the errors are and click 'Clear Console' BEFORE refreshing the page.
It should be close to error free now.
You can also use the developer tools window to debug javascript. It's a very handy window.
In google Chrome it's also F12 to open a similar tools window
In firefox it's ctrl+shift+k (errors) and ctrl+shift+s (debug)
Then press F12, a 'developers tools' window opens.
Now press refresh in the normal IE window.
After that go to the tools window, click on the script tab. And there on the right under 'console' it will list any Javascript error.
Should look like:

It states it's missing a '}' at line 36.
Line 36 is the end of the script part - So what that means is you didn't close a brace where you've opened one.
I've pointed that out as error in my previous post as
- still missing that one.} //missing
After you've edited the file, and refreshed the browsers you'll see that in the tools window it still shows the error. But that's the error from the previous run, so no worries.
You can avoid this by right clicking where the errors are and click 'Clear Console' BEFORE refreshing the page.
It should be close to error free now.
You can also use the developer tools window to debug javascript. It's a very handy window.
In google Chrome it's also F12 to open a similar tools window
In firefox it's ctrl+shift+k (errors) and ctrl+shift+s (debug)
#10
Posted 30 October 2012 - 03:51 PM
cool thanks u wish my course would teach us things like that

#11
Posted 31 October 2012 - 12:39 AM
I wish my course did the same
. I used to absolutely HATE javascript in the beginning, for the lack of having a way to find errors.
I was putting alert(..) statements on EVERY odd line to find errors, how far does the program run... Quite horrible.
I'm very glad browsers have got (very) decent Javascript debugging tools now (and I know about them).

I was putting alert(..) statements on EVERY odd line to find errors, how far does the program run... Quite horrible.
I'm very glad browsers have got (very) decent Javascript debugging tools now (and I know about them).
#12
Posted 31 October 2012 - 01:51 PM
sorry i didnt get any notification for this, yeah im certainly hating it atm but imsure it will all come together one day lol
Also tagged with one or more of these keywords: javascript, validate
Language Forums →
HTML, CSS and Javascript →
Userscript is missing something, which I can't find. Someone please fill ItStarted by Sudhareddy, 31 Jan 2019 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
Javascript Closures Help. Unable to save copy of "count' within an IIFE functionStarted by An Alien, 11 Sep 2017 ![]() |
|
![]() |
||
Language Forums →
HTML, CSS and Javascript →
What is JavaScript used for?Started by dasswadesh, 25 Feb 2017 ![]() |
|
![]() |
||
Tutorial Forums →
HTML, CSS and Javascript Tutorials →
Google Map cannot be displayed Inside Bootstrap Modal ViewStarted by mutago, 31 Jan 2017 ![]() |
|
![]() |
||
Language Forums →
Other Languages →
ASP, ASP.NET and Coldfusion →
Multiple dropdowns that share the same dataStarted by Tchpowdog, 20 Sep 2016 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download