Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Javascript... simple question

Thread Tools
 
Search this Thread
 
Old May 7, 2002 | 06:13 PM
  #1  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

I used to be able to do this sort of thing... but its easier to ask here...

Simple HTML form..

two option buttons

Example

[ ]Male
[ ]Female

Button (Continue)

Javascript to redirect you to either male.htm or female.htm

(these are examples)

I could do this really easily in any other language but theres too many { } == and stuff to get my head around...

Cheers

David
Reply
Old May 7, 2002 | 06:18 PM
  #2  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

Also whats the easiest way of checking that a lot of mandatory fields are completed?

David
Reply
Old May 7, 2002 | 08:05 PM
  #3  
stevem2k's Avatar
stevem2k
Scooby Regular
 
Joined: Sep 2001
Posts: 4,670
Likes: 0
From: Kingston ( Surrey, not Jamaica )
Post

This should get you on the way ......

A simple script for user details validation

Cheers
SteveM


<SCRIPT LANGUAGE=javascript>

function submitThis(){
var submit = 1
var uform = document.forms[0]
if(uform.lname.value == ''){
alert("USER ERROR:\n\nPlease complete the field:\n\nYour surname")
uform.lname.focus()
submit = 0
return false
}
if(uform.fname.value == ''){
alert("USER ERROR:\n\nPlease complete the field:\n\nYour forenames")
uform.fname.focus()
submit = 0
return false
}
if(uform.address1.value == ''){
alert("USER ERROR:\n\nPlease complete the field:\n\nYour address1")
uform.address1.focus()
submit = 0
return false
}
if(uform.city.value == ''){
alert("USER ERROR:\n\nPlease complete the field:\n\nYour city")
uform.city.focus()
submit = 0
return false
}
if(uform.zip.value == ''){
alert("USER ERROR:\n\nPlease complete the field:\n\nYour zip/Post code")
uform.zip.focus()
submit = 0
return false
}

if(uform.txtTelDay.value != ''){
if(isNaN(uform.txtTelDay.value)){
alert("USER ERROR:\n\nYour telephone number should contain numbers only")
uform.txtTelDay.focus()
submit = 0
return false
}
}else{
alert("USER ERROR:\n\nYour telephone number is blank")
uform.txtTelDay.focus()
submit = 0
return false
}

if(uform.email.value != ""){ // checks for a blank field
if(uform.email.value.indexOf(".") == -1 || uform.email.value.indexOf("@") == -1){ // checks for . & @, returns -1 if it cannot find it
alert("USER ERROR\n\nEmail address incorrectly formatted, please check and try again")
uform.email.focus()
submit = 0
return false
}
}else{
alert("USER ERROR:\n\nPlease complete your email address")
uform.email.focus()
submit = 0
return false
}


if(uform.selwhere.options[uform.selwhere.selectedIndex].text == '' && uform.specify.value == ''){
alert("USER ERROR:\n\nPlease complete the fields:\n\nWhere did you hear about us? or Please Specify")
uform.selwhere.focus()
submit = 0
return false
}
if(submit == 1){
document.AppForm.submit()
}else{
return false
}
}




/*//-->*/
</SCRIPT>
Reply
Old May 7, 2002 | 09:42 PM
  #4  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

Sorted.. .Just wondered if there was any easy way like using a function or something... so You could just have an array with the field names and the errors or something...

David
Reply
Old May 8, 2002 | 02:31 PM
  #5  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

btt
Reply
Old May 8, 2002 | 03:56 PM
  #6  
legacyPete's Avatar
legacyPete
Scooby Regular
 
Joined: Dec 2001
Posts: 202
Likes: 0
Post

I wrote this one a while ago:

function verifyForm() {
with(document.forms[0]) {
var msg = "";
// the form fields:
var required = new Array("title", "fname");

// error messages:
var errorMsg = new Array("You must enter a title","Please enter your first name");

for(i = 0; i < required.length; i++) {
myvar = eval(required[i]+".value");
if(!myvar){
if(msg) {
msg += "\n";
}
msg += errorMsg;
}
}

if(msg) {
alert(msg);
} else {
submit();
}
}
}


[Edited by legacyPete - 5/8/2002 3:57:02 PM]

[Edited by legacyPete - 5/8/2002 3:57:27 PM]
Reply
Old May 8, 2002 | 08:22 PM
  #7  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

Cheers... anybody got any ideas for the first... should be pretty easy... but me not knowing javascript.. and not wanting to use vbscript...

David
Reply
Old May 9, 2002 | 04:49 PM
  #8  
David_Wallis's Avatar
David_Wallis
Thread Starter
Scooby Regular
 
Joined: Nov 2001
Posts: 15,239
Likes: 1
From: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Post

Cheers Ill give that a go.

David
Reply
Old Aug 5, 2002 | 09:56 PM
  #9  
legacyPete's Avatar
legacyPete
Scooby Regular
 
Joined: Dec 2001
Posts: 202
Likes: 0
Post

You should have two option elements called sex. One with a checked value of male, one female or whatever:

<input type="radio" name="sex" value="male">
<input type="radio" name="sex" value="female">

When the form's submitted you just check the values:

[i]
var myAction;
with(document.forms[0]) {
for(i=0; i<sex.length; i++)
{
if(sex[i].checked) {
myAction = sex.value;
}
}
}
if(myAction) {
top.location = myAction + ".htm";
} else {
alert("Please select a sex");
}


This way you can just add new option buttons with values, and you wont have to change the script

>> Edit <<
Can't figure out how to show code on this site - click to edit my message to see the proper code as it's been outputted differently to what it should be

[Edited by legacyPete - 5/8/2002 9:59:43 PM]

[Edited by legacyPete - 5/8/2002 10:02:11 PM]

[Edited by legacyPete - 5/8/2002 10:03:49 PM]
Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
Brzoza
Engine Management and ECU Remapping
1
Oct 2, 2015 05:26 PM
Phil3822
ScoobyNet General
33
Oct 2, 2015 03:22 AM
Subaruswan
ScoobyNet General
14
Oct 1, 2015 08:05 PM
Phil3822
General Technical
0
Sep 30, 2015 06:29 PM




All times are GMT +1. The time now is 10:36 AM.