Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,149,874 members, 7,806,499 topics. Date: Tuesday, 23 April 2024 at 05:25 PM

Help with Javascript headache - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help with Javascript headache (1288 Views)

Building A Word Scramble Game With Javascript (text Based) / How To Get A User IP Address With Javascript / Hashtag Highlighting Like Twitter With Javascript (2) (3) (4)

(1) (Reply) (Go Down)

Help with Javascript headache by IAH(f): 5:50pm On Jun 06, 2005
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!
Re: Help with Javascript headache by demmy(m): 6:09pm On Jun 06, 2005
Here is some code from a javascript book I have.



<!-- 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,cool=="required"wink {
if (((tempobj.type=="text"||tempobj.type=="textarea"wink&&
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."wink;
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' !! -->


Re: Help with Javascript headache by jogego(m): 7:09pm On Jun 06, 2005
What you are trying to do is more or less validate ur user input. I dont 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

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

<%
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
Re: Help with Javascript headache by IAH(f): 7:28pm On Jun 06, 2005
Thnaks guys! I'll go try it out and give you feedback on it. grin
Re: Help with Javascript headache by Seun(m): 7:41pm On Jun 06, 2005
So there are javascript and ASP gurus on this site. Interesting.
Re: Help with Javascript headache by Hunter(m): 12:11am On Jun 07, 2005
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/
Re: Help with Javascript headache by modpluz(m): 3:57am On Dec 27, 2005
demmy, you mind putting the copyright(that you ripped off) on that javascript code.
Re: Help with Javascript headache by demmy(m): 2:45pm On Dec 27, 2005
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.
Re: Help with Javascript headache by modpluz(m): 11:59pm On Dec 30, 2005
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...).
Re: Help with Javascript headache by sbucareer(f): 3:05am On Feb 23, 2006


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?


(1) (Reply)

Programmers Networking Community / Hardware Programming Using PIC PROGRAMMING / Vacancies For Programmers [abuja]

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 19
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.