krystyna93
11-12-2007, 05:11 AM
hello there,
i have got a javascript code below that has been modified smaller than what is originally was, and im hoping someone can develop a flowchart based on it.
I have done two other flowcharts for my other task exercises for study, but am finding it hard to develop one for the form below which has extra
'if' problems to the parent 'else if', if that makes sense...
I have done an iteration loop and a sequence flowchart, but this one is proving to be the hardest of them all, or could be much easier than i realize!
your help will be greatly appreciated!
p.s. i have tried uploading the other flowcharts i have done, but it only asks for a URL instead of the option of 'browse' to find the image on my computer...
------------------------------
function checkForm()
{
if the phone number input field is empty
else if (document.getElementById("phone").value == "")
{
//do the following:
window.alert("Please enter your telephone number");//bring up error message
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
if(document.getElementById("phone").value.search(/\d{4}\-\d{4}/)==-1)
//check phone field has 4 numbers than a dash than another 4 numbers and if there is one omitted
{
//do the following:
alert("The phone number you entered is not valid.\r\n Please enter a phone number with the format xxxx-xxxx.");//bring up error message
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
var min=9;//a variable of a minimum of 9 numbers
if(document.getElementById("phone").value.length != min)//if the length of the phone number is minimum of 9 digits only
{
//do the following:
alert("The phone number you entered is not valid.\r\n Please enter a phone number with a maximum length of xxxx-xxxx (9).");//bring error message up
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
//else if the suburb input field is empty
else if (document.getElementById("suburb").value == "")
{
//do the following:
window.alert("Please enter your suburb area");//bring up error message
document.getElementById("suburb").focus();//put focus back in field
return false;//stop
}
//else if postcode input field is empty
else if (document.getElementById("postcode").value == "")
{
//do the following:
window.alert("Please enter your postcode");//bring up error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
var postcode = new String("1234");//a variable with a string of 4 numbers
if (document.getElementById("postcode").value.length !=4)//if the postcode is not equal to 4
{
//do the following:
alert("Your postcode must contain four numbers only!");//bring up error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
var postcode = new String("1234");//a variable ith a string of four numbers
if (isNaN(document.getElementById("postcode").value)) //if the postcode is not numbers
{
alert ("Please enter only numbers!");//bring up the error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
//else if the email input field is empty
else if (document.getElementById("email").value == "")
{
//do the following:
window.alert("Please enter your email address!");//bring up error message
document.getElementById("email").focus();//put focus back in field
return false;//stop
}
var email = document.getElementById("email");
//variables to remember the position of the "@" and "." symbols
var atPos = email.value.indexOf("@");
var dotPos = email.value.indexOf(".");
if (dotPos <1 || atPos <1 || dotPos - atPos <2 || email.value.length <3)
{
window.alert("Please enter a valid email address!");//bring up error message
document.getElementById("email").focus();//put focus back in field
return false;//stop
}
//else if the credit card is not selected which is equal to zero
else if(document.getElementById("card").selectedIndex == 0)
{
//do the following:
alert("Please select your credit card");//bring up error message
document.getElementById("card").focus();//put focus back in field
return false;//stop
}
{
return true;//submit form when all fields are full
}
i have got a javascript code below that has been modified smaller than what is originally was, and im hoping someone can develop a flowchart based on it.
I have done two other flowcharts for my other task exercises for study, but am finding it hard to develop one for the form below which has extra
'if' problems to the parent 'else if', if that makes sense...
I have done an iteration loop and a sequence flowchart, but this one is proving to be the hardest of them all, or could be much easier than i realize!
your help will be greatly appreciated!
p.s. i have tried uploading the other flowcharts i have done, but it only asks for a URL instead of the option of 'browse' to find the image on my computer...
------------------------------
function checkForm()
{
if the phone number input field is empty
else if (document.getElementById("phone").value == "")
{
//do the following:
window.alert("Please enter your telephone number");//bring up error message
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
if(document.getElementById("phone").value.search(/\d{4}\-\d{4}/)==-1)
//check phone field has 4 numbers than a dash than another 4 numbers and if there is one omitted
{
//do the following:
alert("The phone number you entered is not valid.\r\n Please enter a phone number with the format xxxx-xxxx.");//bring up error message
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
var min=9;//a variable of a minimum of 9 numbers
if(document.getElementById("phone").value.length != min)//if the length of the phone number is minimum of 9 digits only
{
//do the following:
alert("The phone number you entered is not valid.\r\n Please enter a phone number with a maximum length of xxxx-xxxx (9).");//bring error message up
document.getElementById("phone").focus();//put focus back in field
return false;//stop
}
//else if the suburb input field is empty
else if (document.getElementById("suburb").value == "")
{
//do the following:
window.alert("Please enter your suburb area");//bring up error message
document.getElementById("suburb").focus();//put focus back in field
return false;//stop
}
//else if postcode input field is empty
else if (document.getElementById("postcode").value == "")
{
//do the following:
window.alert("Please enter your postcode");//bring up error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
var postcode = new String("1234");//a variable with a string of 4 numbers
if (document.getElementById("postcode").value.length !=4)//if the postcode is not equal to 4
{
//do the following:
alert("Your postcode must contain four numbers only!");//bring up error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
var postcode = new String("1234");//a variable ith a string of four numbers
if (isNaN(document.getElementById("postcode").value)) //if the postcode is not numbers
{
alert ("Please enter only numbers!");//bring up the error message
document.getElementById("postcode").focus();//put focus back in field
return false;//stop
}
//else if the email input field is empty
else if (document.getElementById("email").value == "")
{
//do the following:
window.alert("Please enter your email address!");//bring up error message
document.getElementById("email").focus();//put focus back in field
return false;//stop
}
var email = document.getElementById("email");
//variables to remember the position of the "@" and "." symbols
var atPos = email.value.indexOf("@");
var dotPos = email.value.indexOf(".");
if (dotPos <1 || atPos <1 || dotPos - atPos <2 || email.value.length <3)
{
window.alert("Please enter a valid email address!");//bring up error message
document.getElementById("email").focus();//put focus back in field
return false;//stop
}
//else if the credit card is not selected which is equal to zero
else if(document.getElementById("card").selectedIndex == 0)
{
//do the following:
alert("Please select your credit card");//bring up error message
document.getElementById("card").focus();//put focus back in field
return false;//stop
}
{
return true;//submit form when all fields are full
}