View Full Version : Helped Needed: JavaScript Basics

25-06-2004, 19:42:24

I need to JavaScript a web page so that it won't let users leave the page when they click the "Submit" button if 3 specific text input fields (normal text boxes) are empty (popping up a "Naughty User! Fill in the required fields!" would be nice as well). You JavaScript experienced are welcome to post example code or links to such.

Thanks for code, info, or links in advance.

25-06-2004, 21:42:57
Did you say COBOL?

Sir Penguin
25-06-2004, 21:59:30
Yes, please do it in COBOL.


25-06-2004, 22:15:51
COBOL doesn't run client-side on old Macs. So I need it in JavaScript.

Honestly, I expected to have seen a link from our webbies on their favorite sources by now. But it seems football is currently holding all their attention.

I don't mind doing some reading and figuring matters out on my own (I am a programmer, after all)... but I need to get this whacked out by the end of Monday or Tuesday at the latest to get it all tested so it can be approved for an "emergency" roll out (meaning, we publish the page update and don't tell anyone).

And posting this here (asking for help/links) let's me keep CG firmly planted in the "work related" list of sites. ;)

Sir Penguin
25-06-2004, 22:21:45
I recommend www.google.ca.


25-06-2004, 22:38:34
Well, I intend to use www.google.com Monday. And maybe some msdn.microsoft.com if I *have* to (depending on what my MSDN DVD Library spits up). But honestly, with the amount of webbies we have here, I expected a quick pointer to a good "basic" or "beginner" javascript site. Or even a couple of code snippets. Unlike some people and their C code requests, I'm not asking people to write and debug it for me...

Now, if you, SP, don't know, that's fine. You are more a Python person, aren't you? Venom is a webbie, but I don't recall what flavors. Mikie is mostly a PHP webbie, isn't he?

26-06-2004, 08:12:10
Try here...and quit whining

If that isn't what you're looking for then ask again and maybe someone will help, but not likely on a weekend.

26-06-2004, 13:23:12
Yeah, ask again on Monday. I'm getting ready to leave but I'll help then.

26-06-2004, 13:29:45
put this code inbetween the <head></head> tags.

<script language="JavaScript" type="text/javascript">

function checkform ( form )
if (form1.company.value == "") {
alert( "Please enter your Company Mame." );
return false ;
if (form1.contact.value == "") {
alert( "Please enter your Contact Name." );
return false ;
return true ;

Then make sure that the form tag is like this:

<form action="yourscript.php" method="post" name="form1" onsubmit="return checkform(this);">

just make sure the field names match in the form. There's slightly more involved for checking a dropdown is selected. I don't have that code to hand.

26-06-2004, 13:31:20
Here. Couple of ways to do it. This one's pretty simple and quick Try this.

function chkdes(){
if (document.groupform.RequiredField.value==""){
alert("Please enter a Designer First Name.");
return false;
if (document.groupform.RequiredField2.value==""){
alert("Please enter a Designer Last Name.");
return false;

and to execute that code in the form tag that matches with the submit button use something like this:

form method="POST" action="whatever.asp" name="groupform" onsubmit="return chkdes();"

Hopefully that helps. If not, well, there's a reason I'm unemployed, isn't there?

26-06-2004, 13:32:21
God damn you nav. And I tried on that. And yours is probably still better.

26-06-2004, 13:33:57
ha beat you. :lol:

yeah and edit out that less than one shit (<1). ;)

26-06-2004, 13:35:22
Yeah, that was retarded.

26-06-2004, 13:37:35
I was half thinking checking the length of the string as that's actually faster than comparing to a blank.

26-06-2004, 14:35:17
is it? not that you'd notice really.

27-06-2004, 00:28:06
Supposedly. But as you said, you'd never notice on an order of magnitude this small.

28-06-2004, 18:02:33
Thanks gang! :D

28-06-2004, 18:53:23
Worked like a charm. Thanks again! Especially to Nav and Venom!

And this makes another tick mark for CG in the "Work related" column for me. :cool:

28-06-2004, 20:49:35
You used Nav's, didn't you? Goddamn I'm a failure.

28-06-2004, 20:59:15
Bit of both, actually. And you guys really helped out. Thanks again! :D

I had a flood of "examples" come in from various teams and groups at work today, as word went out I was going to need a ~simple~ JavaScript example to do that. And they all sent these monster files (200 Kb is the smallest!) of their pages to do such a thing. And interesting links... but not to any JavaScripting sites. Which is par for the course around here. ;)

28-06-2004, 21:02:20
When you need simple, come to the simplest. Me!

28-06-2004, 21:16:11
I'll remember that for the future. :)

28-06-2004, 21:21:24
A little sample of the goods. 2+2=4

Immortal Wombat
28-06-2004, 21:23:50
var NumberInput = 2;
for(i = 0; i < 1; i = i ++){
NumberInput = NumberInput + NumberInput;
return NumberInput;