Help with Javascript headache

A Member? Please Login  
type your username and password to login
Date: July 06, 2008, 10:32 AM
216353 members and 122091 Topics
Latest Member: amusnelmevawl 2004 avalon
Nairaland [Nigerian Forum] Home Help Search Who is currently online? Login Register
Nairaland Forum  |  Technology  |  Programming  |  Help with Javascript headache
Pages: (1) Go Down Send this topic Notify of replies
Author Topic: Help with Javascript headache  (Read 978 views)
IAH (f)
Help with Javascript headache
« on: June 06, 2005, 05:50 PM »

Computer gurus, where are you??? Please help a newbie with this.
I am trying to make a form for a website. I've finished it but I want to use javascript to validate some required fields before submission of the form. Ok, let me explain better. The form requires a user to fill in stuffs like Name, Email address, etc. But you know some people might not fill certain fields. So if a user tries to submit without filling his name, for example, I want a messagebox/dialogbox to pop up and say "Please enter your name" or something like that. I have tried it but it's not working so please help!!!!!!!! I'm having headache already o!
demmy (m)
Re: Help with Javascript headache
« #1 on: June 06, 2005, 06:09 PM »

Here is some code from a javascript book I have.

Code:

<!-- TWO STEPS TO INSTALL BASIC VALIDATION:

  1.  Copy the coding into the HEAD of your HTML document
  2.  Add the last code into the BODY of your HTML document  -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed.");
return false;
}
else
return true;
}
//  End -->
</script>

<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->

<center>
<form onSubmit="return checkrequired(this)">

<input type="text" name="requiredname">
<br>
<input type="text" name="requiredemail">
<br>
<select name="requiredhobby">
<option selected>Pick an option!
<option>1
<option>2
<option>3
</select>
<br>
<textarea name="requiredcomments"></textarea>
<br>
<input type=submit value="Submit">
</form>
</center>

<!-- The first option in your pulldown menus must be set to 'selected' !! -->


jogego (m)
Re: Help with Javascript headache
« #2 on: June 06, 2005, 07:09 PM »

What you are trying to do is more or less validate your user input. I don't use pop ups for this cs most people who are security conscious normally disable pop ups nowadays. For now, I normallly do my scripting in ASP and for data validation my codes go something like:

Function Check
Check = False
' Check for Name and password
if len(varName) < 1 Then
   %><title>Sport Club:Wrong details</title>


   You must enter a Name<br />
   <%
   Exit Function
End if
if len(varPassword) < 1 Then
   %><title> Sport Club:Wrong details</title>
   You must enter a Password<br />
   <%
   Exit Function
End if
Check = True
End Function

This directs the user to a page displayin the error message. If you need any more help, I'd be glad to assist
IAH (f)
Re: Help with Javascript headache
« #3 on: June 06, 2005, 07:28 PM »

Thnaks guys! I'll go try it out and give you feedback on it.  Grin
Seun (m)
Re: Help with Javascript headache
« #4 on: June 06, 2005, 07:41 PM »

So there are javascript and ASP gurus on this site.  Interesting.
Hunter (m)
Re: Help with Javascript headache
« #5 on: June 07, 2005, 12:11 AM »

personally I would see if your host is compatable with PHP as it allows alot more feature rich websites, and there alot of pre written scripts people have written to help get a good website.

You can find some good scripts for both java and PHP and several other languages at http://www.hotscripts.com/
modpluz (m)
Re: Help with Javascript headache
« #6 on: December 27, 2005, 03:57 AM »

demmy, you mind putting the copyright(that you ripped off) on that javascript code.
demmy (m)
Re: Help with Javascript headache
« #7 on: December 27, 2005, 02:45 PM »

Ripped off heh? If you had read my post you would have been informed that I never claimed the code as my own so no need for any "uncovering". As for inserting copyright I don't mind, only the original author never put it there so I never bothered myself either. And for your information I recieved no kobo for that code. I swear.     
modpluz (m)
Re: Help with Javascript headache
« #8 on: December 30, 2005, 11:59 PM »

demmy, me was just kidding ni oooo. who go pay you for that code(only if they don't know easy it is to get it to work).
but you know thats one good part of been a programmer(to you its a piece of cake, but to others...).
sbucareer (m)
Re: Help with Javascript headache
« #9 on: February 23, 2006, 03:05 AM »



Another way to accomplish this is to write triggers at your database level. The only downside is that the user is not aware of your application rules until he/she tries to submit the form for processing at the server.

You can get your DBA to writer PL/SQL triggers and other business rules at the DML level. What you do now is to warn the users by putting red * near the field that you want to collect the inforation that this is a required field.

If the user is stupid enough to over look your warning, they will meet their match at the submission part.

NB
=========

I was assuming it is a database solution since you are collecting information, possibility is, you will store them. Otherwise why collect inforation?


 Web Applications Are Not The Way Out  Microsft Visual Studio 2008 Beta  Software Packaging  Page 2
Pages: (1) Go Up Send Topic to Friend by E-mail Reply 
Google
 
Web www.nairaland.com
Sections: TV/Movies (2) Music/Radio (2) Celebrities Jobs (2) Career Romance Books Politics Sports Fashion Travel
Health Schooling Religion General(2) Business Webmaster Programming Computers Phones Cars & Trucks

Links: Page1 Page2 Page3 Page4 Page5 Page6 Page7 Page8 Page9 Page10

Nairaland is owned by Oluwaseun Osewa
Nairaland Forum | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.