Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2011
    Location
    wisconsin
    Posts
    21
    Thanks
    9
    Thanked 0 Times in 0 Posts

    checking for the existance of cookies

    Hello, codingForums Pals

    I have a little inconsistency with a html form I am designing for a class assignment. In the assignment I have to execute javascript code on the page load that checks for the presence of existing cookies in the page, if no cookies were found, an alerts pops saying so. for this I embedded a function called "existing_cookies()" in the "window.onload" event that will check for cookies when the page loads por however for some extraneous reason the code sits unresponsive, I get no alert for that matter.

    here is the code if someone can help me solve this puzzle
    Code:
    <html>
    <head>
    <title>Bagels order</title>
    <style type type="text/css">
    .heading{font-weigth:bold ; font-family:"comic sans ms"; font-size:30pt}
    .subheading{font-weigth:bold ; font-family:"comic sans ms"; font-size:20pt}
    .body{font-family:"comic sans ms"; font-size:8.5pt; font-weight:bold}
    table{background-image:url(stucco.jpg)}
    </style>
    <script type="text/javascript">
    
    window.onload=existing_cookies; //onload event handler that runs existing_cookies()
    
    function existing_cookies();
    {
    	if(document.cookie.length==0)
    	alert("No Default Bagel Order Information found");
    	
    }
    
    function order_bagels()
    {
    	
    }
    </script>
    
    
    </head>
    <body>
    <form name="myform">
    <table border="1" width="100%">
    <tr><td class="heading">Bernies Bagels Barn</td><td align="center" colspan="3"><img src="bagel.jpg" width="320px" height="240px"/></td></tr>
    <tr align="center" class="body"><td>Bagel Type</td><td>Cream Cheese</td><td colspan="2">Quantity</td></tr>
    <table border="1" width="49%" align="left">
    <tr><td colspan="1" align="left" class="body">Cinammon</td></tr>
    <tr><td colspan="1" align="left" class="body">Apple</td></tr>
    <tr><td colspan="1" align="left" class="body">Chocolate Chip</td></tr>
    <tr><td colspan="1" align="left" class="body">Egg</td></tr>
    <tr><td colspan="1" align="left" class="body">Whole Wheaty</td></tr>
    </table>
    <table border="1" width="5%" align="left">
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    </table>
    <table border="1" class="body" align="left" width="23%">
    <tr><td align="left">Plain</td></tr>
    <tr><td align="left">Low Fat Plain</td></tr>
    <tr><td align="left">Garlic</td></tr>
    <tr><td align="left">Cinnamon</td></tr>
    <tr><td align="left">Fruit</td></tr>
    </table>
    <table class="body" border="0" width="23%" align="left">
    <tr><td align="center"><input type="checkbox" name="plain"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="low_fat"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="garlic"/></td><td><input type="radio" name="qt"/>1/2 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="cinnamon"/></td><td><input type="radio" name="qt"/>1 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="fruit"/></td></tr>
    </table>
    <table border="1" width="100%">
    <tr><td colspan="3" class="subheading" align="center">Functions</td></tr>
    <tr align="center"><td><input type="button" value="Delete Default Order"/></td><td><input type="button" value="Make a New Default"/></td><td><input type="button" value="Load Default Order"/></td></tr>
    <tr align="center"><td>Visits:<input type="text" size="3" readonly /></td><td><input type="button" value="Order Bagels" onclick="order_bagels()"/></td><td>Orders Placed:<input type="text" size="3" readonly /></td></tr>
    </table>
    </table>
    </form>
    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Delete the highlighted
    Code:
    <html>
    <head>
    <title>Bagels order</title>
    <style type type="text/css">
    .heading{font-weigth:bold ; font-family:"comic sans ms"; font-size:30pt}
    .subheading{font-weigth:bold ; font-family:"comic sans ms"; font-size:20pt}
    .body{font-family:"comic sans ms"; font-size:8.5pt; font-weight:bold}
    table{background-image:url(stucco.jpg)}
    </style>
    <script type="text/javascript">
    
    window.onload=existing_cookies; //onload event handler that runs existing_cookies()
    
    function existing_cookies(); // delete this ;
    {
    	if(document.cookie.length==0)
    	alert("No Default Bagel Order Information found");
    	
    }
    
    function order_bagels()
    {
    	
    }
    </script>
    
    
    </head>
    <body>
    <form name="myform">
    <table border="1" width="100%">
    <tr><td class="heading">Bernies Bagels Barn</td><td align="center" colspan="3"><img src="bagel.jpg" width="320px" height="240px"/></td></tr>
    <tr align="center" class="body"><td>Bagel Type</td><td>Cream Cheese</td><td colspan="2">Quantity</td></tr>
    <table border="1" width="49%" align="left">
    <tr><td colspan="1" align="left" class="body">Cinammon</td></tr>
    <tr><td colspan="1" align="left" class="body">Apple</td></tr>
    <tr><td colspan="1" align="left" class="body">Chocolate Chip</td></tr>
    <tr><td colspan="1" align="left" class="body">Egg</td></tr>
    <tr><td colspan="1" align="left" class="body">Whole Wheaty</td></tr>
    </table>
    <table border="1" width="5%" align="left">
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel_type"/></td></tr>
    </table>
    <table border="1" class="body" align="left" width="23%">
    <tr><td align="left">Plain</td></tr>
    <tr><td align="left">Low Fat Plain</td></tr>
    <tr><td align="left">Garlic</td></tr>
    <tr><td align="left">Cinnamon</td></tr>
    <tr><td align="left">Fruit</td></tr>
    </table>
    <table class="body" border="0" width="23%" align="left">
    <tr><td align="center"><input type="checkbox" name="plain"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="low_fat"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="garlic"/></td><td><input type="radio" name="qt"/>1/2 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="cinnamon"/></td><td><input type="radio" name="qt"/>1 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="fruit"/></td></tr>
    </table>
    <table border="1" width="100%">
    <tr><td colspan="3" class="subheading" align="center">Functions</td></tr>
    <tr align="center"><td><input type="button" value="Delete Default Order"/></td><td><input type="button" value="Make a New Default"/></td><td><input type="button" value="Load Default Order"/></td></tr>
    <tr align="center"><td>Visits:<input type="text" size="3" readonly /></td><td><input type="button" value="Order Bagels" onclick="order_bagels()"/></td><td>Orders Placed:<input type="text" size="3" readonly /></td></tr>
    </table>
    </table>
    </form>
    </body>
    </html>
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • #3
    New Coder
    Join Date
    Mar 2011
    Location
    wisconsin
    Posts
    21
    Thanks
    9
    Thanked 0 Times in 0 Posts
    hi there, thanks for your thoughtful response, I did erase the highlighted parts, despite the function either doesn't get called or it does get called but it doesn't execute,

  • #4
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Have you deleted any existing cookies ?

    Try putting an else clause with an alert to prove the function is running.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  • Users who have thanked AndrewGSW for this post:

    lonelywolf (04-30-2011)

  • #5
    New Coder
    Join Date
    Mar 2011
    Location
    wisconsin
    Posts
    21
    Thanks
    9
    Thanked 0 Times in 0 Posts
    no I have not indeed, thanks for such valuable suggestion, I yet have another inconsistency if not too much bother I would like to post it for anyone to take a peek at it. anytime the "order bagels" button is clicked and the order has been processed, I have to add 1 to the textbox next to the "orders places" field, however at the end of script execution nothing gets added to that field, the purpose for such thing it to keep track of how many times orders have been made by a particular user, down below is the code to give a better mock up of the situation.

    Code:
    <html>
    <head>
    <title>Bagels order</title>
    <style type="text/css">
    .heading{font-weigth:bold ; font-family:"comic sans ms"; font-size:30pt}
    .subheading{font-weight:bold ; font-family:"comic sans ms"; font-size:20pt}
    .body{font-family:"comic sans ms"; font-size:8.5pt; font-weight:bold}
    table{background-image:url(stucco.jpg)}
    </style>
    <script type="text/javascript">
    
    function existing_cookies()
    {
    	if(document.cookie.length==0)
    	{
    	alert("No Default Bagel Order Information found");
    	}
    }
    
    function order()
    {
    	var f = document.myform;
    	var ordernum = 0;
    	
    	if((f.bagel[0].checked && f.qt[0].checked) || (f.bagel[0].checked && f.qt[1].checked)) 
    	{
    	ordernum==ordernum++;
    	document.myform.total.value=ordernum;
    	alert("your order has been processed");
    	
    	}
    	
    	else if ((f.bagel[1].checked && f.qt[0].checked) || (f.bagel[1].checked && f.qt[1].checked))
    	alert("your order has been processed");
    	
    	else if ((f.bagel[2].checked && f.qt[0].checked) || (f.bagel[2].checked && f.qt[1].checked))
    	alert("your order has been processed");
    	
    	else if ((f.bagel[3].checked && f.qt[0].checked) || (f.bagel[3].checked && f.qt[1].checked))
    	alert("your order has been processed");
    	
    	else if ((f.bagel[4].checked && f.qt[0].checked) || (f.bagel[4].checked && f.qt[1].checked))
    	alert("your order has been processed");
    	
    	else
    	alert("make sure that you selected a bagel type and quantity");
    }
    </script>
    
    
    </head>
    <body onload="existing_cookies()">
    <form name="myform">
    <table border="1" width="100%">
    <tr><td class="heading">Bernies Bagels Barn</td><td align="center" colspan="3"><img src="bagel.jpg" width="320px" height="240px"/></td></tr>
    <tr align="center" class="body"><td>Bagel Type</td><td>Cream Cheese</td><td colspan="2">Quantity</td></tr>
    <table border="1" width="49%" align="left">
    <tr><td colspan="1" align="left" class="body">Cinammon</td></tr>
    <tr><td colspan="1" align="left" class="body">Apple</td></tr>
    <tr><td colspan="1" align="left" class="body">Chocolate Chip</td></tr>
    <tr><td colspan="1" align="left" class="body">Egg</td></tr>
    <tr><td colspan="1" align="left" class="body">Whole Wheaty</td></tr>
    </table>
    <table border="1" width="5%" align="left">
    <tr><td align="center"><input type="radio" name="bagel"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel"/></td></tr>
    <tr><td align="center"><input type="radio" name="bagel"/></td></tr>
    </table>
    <table border="1" class="body" align="left" width="23%">
    <tr><td align="left">Plain</td></tr>
    <tr><td align="left">Low Fat Plain</td></tr>
    <tr><td align="left">Garlic</td></tr>
    <tr><td align="left">Cinnamon</td></tr>
    <tr><td align="left">Fruit</td></tr>
    </table>
    <table class="body" border="0" width="23%" align="left">
    <tr><td align="center"><input type="checkbox" name="plain"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="low_fat"/></td></tr>
    <tr><td align="center"><input type="checkbox" name="garlic"/></td><td><input type="radio" name="qt"/>1/2 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="cinnamon"/></td><td><input type="radio" name="qt"/>1 Dozen</td></tr>
    <tr><td align="center"><input type="checkbox" name="fruit"/></td></tr>
    </table>
    <table border="1" width="100%">
    <tr><td colspan="3" class="subheading" align="center">Functions</td></tr>
    <tr align="center"><td><input type="button" value="Delete Default Order"/></td><td><input type="button" value="Make a New Default"/></td><td><input type="button" value="Load Default Order"/></td></tr>
    <tr align="center"><td>Visits:<input type="text" size="3" readonly /></td><td><input type="button" value="Order Bagels" onclick="order()"/></td><td>Orders Placed:<input type="text" size="3" name="total" readonly  /></td></tr>
    </table>
    </table>
    </form>
    </body>
    </html>

  • #6
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    ordernum==ordernum++;
    // ??

    Code:
    ordernum++;    // or
    ordernum = ordernum + 1;
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •