Welcome to WebmasterWorld Guest from 107.22.87.205

Forum Moderators: open

Message Too Old, No Replies

javascript functions

How to end function early

     
12:38 pm on May 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If anyone has a minute to look at this script, could you tell me how to make the function end after an alert. I set the select box description(size and color) as the selected values, but want the function to end if they didn't make a valid choice. I know it would be easy enough to just take that value out of the form, but I know there is a way to do it. Anyway, here it is:
<script language="JavaScript">
function buildOrder()
{
var picksize="Please choose a size."
var pickcolor="Please choose a color."
var dcolor=document.dressopts.colorchoice.value;
if(dcolor=="colors")
{alert(pickcolor)}
var dsize=document.dressopts.sizechoice.value;
if(dsize=="sizes")
{alert(picksize)}
if(dsize=="4")
{cost="119"}
if(dsize=="5")
{cost="119"}
if(dsize=="6")
{cost="119"}
if(dsize=="7")
{cost="119"}
if(dsize=="8")
{cost="119"}
if(dsize=="10")
{cost="129"}
if(dsize=="12")
{cost="129"}
if(dsize=="14")
{cost="129"}
var desc="Your dress size is " + dsize + ". " + dcolor + " is your color choice. Your final cost for this dress is " + cost + ". And remember shipping is absolutely free!!!";
alert(desc)
var sOrder = "https://www.paypal.com/cart/add=1&business=m00n106%40aol.com&item_name=Flower girl dress(" + dcolor + ")(size " + dsize + ")&item_number=fgd88030&amount=" + cost;
window.open(sOrder,'cartwin','width=600,height=400,scrollbars,location,resizable,status');
}
</script>

Thanks

1:10 pm on May 7, 2002 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You can break up this large function into smaller functions. Alert functions and assignment functions. Call the assignment functions if you don't alert.
1:27 pm on May 7, 2002 (gmt 0)

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Like Korkus said, I would break it up into smaller functions.

You could create flags (boolean variables) that get set when an alert is given. Then you could check the flag - if false you know that they never had a valid selection.

You also might want to look into the "switch" command instead of the else-if in this case.

With switch you can set a default: which would return false. You can also set "break;" to get out of the routine.

Good luck with it. It sounds like a fun project.

2:39 pm on May 7, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>Good luck with it. It sounds like a fun project.

It is fun :) , but time consuming! :o It's my mothers bridal shop site. She hired someone to build it but they only gave her like three pages and no way to even order! :( I got the ftp access and started changing, but didn't realize what I wasw getting into. It'll probably have 400 or more pages, plus, as you can see there are lots of variables in the items. I had just started learning HTML not long before. By the time I finish this site I hopefully have a clue. Anyway thanks again. If, by chance you wanted to check it out, I put it in profile.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month