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 07 May 2002, 06:13 PM
  #1  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
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
Old 07 May 2002, 06:18 PM
  #2  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

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

David
Old 07 May 2002, 08:05 PM
  #3  
stevem2k
Scooby Regular
 
stevem2k's Avatar
 
Join Date: Sep 2001
Location: Kingston ( Surrey, not Jamaica )
Posts: 4,670
Likes: 0
Received 0 Likes on 0 Posts
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>
Old 07 May 2002, 09:42 PM
  #4  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
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
Old 08 May 2002, 02:31 PM
  #5  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

btt
Old 08 May 2002, 03:56 PM
  #6  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
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]
Old 08 May 2002, 08:22 PM
  #7  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
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

Trending Topics

Old 09 May 2002, 04:49 PM
  #8  
David_Wallis
Scooby Regular
Thread Starter
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

Cheers Ill give that a go.

David
Old 05 August 2002, 09:56 PM
  #9  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
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]
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
Phil3822
ScoobyNet General
33
02 October 2015 03:22 AM
Subaruswan
ScoobyNet General
14
01 October 2015 08:05 PM
Phil3822
General Technical
0
30 September 2015 06:29 PM



Quick Reply: Javascript... simple question



All times are GMT +1. The time now is 02:53 PM.