Javascript... simple question
#1
Scooby Regular
Thread Starter
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
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
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
#2
Scooby Regular
Thread Starter
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
Also whats the easiest way of checking that a lot of mandatory fields are completed?
David
David
#3
Scooby Regular
Join Date: Sep 2001
Location: Kingston ( Surrey, not Jamaica )
Posts: 4,670
Likes: 0
Received 0 Likes
on
0 Posts
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>
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>
#4
Scooby Regular
Thread Starter
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
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
David
#6
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]
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]
#7
Scooby Regular
Thread Starter
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
Cheers... anybody got any ideas for the first... should be pretty easy... but me not knowing javascript.. and not wanting to use vbscript...
David
David
Trending Topics
#9
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]
<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]
Thread
Thread Starter
Forum
Replies
Last Post
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
Phil3822
General Technical
0
30 September 2015 06:29 PM