PDA

View Full Version : Need help with flowchart development


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
}

sage45
11-12-2007, 07:57 AM
It's not really that difficult... Pretty much a straight shot of decision boxes...
DECISION----FALSE----End Script
|
|
|
TRUE
|
|
|
DECISION----FALSE----End Script
|
|
|
TRUE
|
|
|
DECISON-----FALSE----End Script
|
|
|
TRUE

etc, etc-saige-

krystyna93
11-12-2007, 10:48 AM
thanks for the reply, sage

so does the chart apply to an 'else if' statement's with extra 'if' statements followed by it?
such as if there are two other if statements asking for the max numbers and also if its a number...? if that makes sense..

christina

sage45
11-12-2007, 07:53 PM
I think you might be confusing:If (condition) Then
{
//Do something for True Case
}
Else If (condition) Then
{
//Do something for First False Case
}
Else If (condition) Then
{
//Do something for Second False Case
}
Else
{
//Do something for the Third False Case
}
End IfFlowchart:

DECISION----FALSE----DECISION----FALSE----DECISION----FALSE----END SCRIPT
| | |
| | |
| | |
TRUE TRUE TRUE
| | |
| | |
END SCRIPT-------------------------------------With:If (condition) Then
{
If (condition) Then
{
//Do something for True Case
}
Else If (condition)
{
//Do something for False Case
}
End If
}
Else
{
If (condition) Then
{
//Do something for True Case
}
Else If (condition)
{
//Do something for False Case
}
End If
}
End IfFlowchart:

DECISION----------------FALSE----------------DECISION----FALSE----END SCRIPT
| |
| |
| |
TRUE----DECISION----FALSE----END SCRIPT TRUE
| | |
| | |
| | |
| TRUE |
| | |
| | |
END SCRIPT--------------------------------------HTH,

-saige-