Jump to content

function not working


conan318

Recommended Posts

<html xmlns="http://www.w3.org/1999/xhtml">

ok i have a simple form which works up into the redirect intead of taking me to checkout.html

its putting the result of the calculation url like this.

www.billysgiftbox/index.html?result=59

 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Billy's Gift Baskets</title>

<link href="main.css" rel="stylesheet" type="text/css">
<script type="text/javascript"> 
<!--
if (document.images)
{
  pic1= new Image(); 
  pic1.src="logo.png"; 

  pic2= new Image(); 
  pic2.src="logo2.png"; 
}
</script>
<SCRIPT language="JavaScript">
function checkout() {


if (result.value==='0'){
alert('Please select an item to purchase')
  

  }
else if (result.value==='NaN'){
alert('Sorry there was an error please try again')
  
  }
else if (result.value!='0')
  {
check()
  }
}
</SCRIPT>
<SCRIPT language="JavaScript">
function check() {
var x=window.confirm("Are you sure you want to check out?")
if (x)
window.location.href="checkout.html";

else
window.location="index.html";
  }
</SCRIPT>
</head>
<body>

  <div class="banner">
    
      <img src="logo.png" name="pic1" border="0"  id="pic1" 
onmouseover="document.pic1.src='logo2.png'"
onmouseout="document.pic1.src='logo.png'">
    </div>
    <div class="content">
  
  <div class="table">
<form action="" name="form1" id="form1" onsubmit"checkout()" >
  <table  border="5" >
    
    <tr>
      <td>Code</td>
      <td>Image</td>
      <td>Item</td>
      <td>Price</td>
      <td>Qty</td>
    </tr>
    <script type="text/javascript" src="test2.js"></script>
    <tr>
       <td colspan=0><input type="button" value="Buynow" onClick="cal(this.form)">
        <input type="reset" value="Clear"/></td>
      <td>Total:</td>
      <td align="center">$
        <input type="text" name="result" id="result" value="0" size=10 onClick="alert('Sorry you cant change the total price ')"></td>
        
        <td colspan=1>
       
        <input type="submit" Value="Checkout" /></td>
     
    </tr>
  </table>
  </form>



</div>
</div>
</body>
</html>

Link to comment
Share on other sites

this is the test.js file which goes with the code i gave you before.

test.js

 

CArray= new Array();
IArray= new Array();
IMGArray= new Array();
PArray= new Array();




CArray[0] = "999";
CArray[1] = "998";
CArray[2] = "997";
CArray[3] = "996";
CArray[4] = "995";
CArray[5] = "994";
CArray[6] = "993";
CArray[7] = "992";
CArray[8] = "991";
CArray[9] = "990";


IArray[0] = "Baby Nappy Cake";
IArray[1] = "Blue Baby Nappy Cake";
IArray[2] = "Canebasket - Include's Champagne and Teddy Bear";
IArray[3] = "Beautiful Gift Hamper";
IArray[4] = "Gift Hamper Wrapped in  Celafain ";
IArray[5] = "Wine Gift Hamper";
IArray[6] = "Mothers' Day Gift Hamper";
IArray[7] = "Champagne Cocktail";
IArray[8] = "Golf and Wine Appreciation";
IArray[9] = "Sweet Valentine";


IMGArray[0] = "bear1.png";
IMGArray[1] = "bear3.jpg";
IMGArray[2] = "bear4.jpg";
IMGArray[3] = "bear5.jpg";
IMGArray[4] = "bear6.jpg";
IMGArray[5] = "bear7.jpg";
IMGArray[6] = "bear8.jpg";
IMGArray[7] = "bear9.jpg";
IMGArray[8] = "bear10.jpg";
IMGArray[9] = "bear11.jpg";


PArray[0] = "40.00";
PArray[1] = "25.00";
PArray[2] = "28.00";
PArray[3] = "35.00";
PArray[4] = "44.00";
PArray[5] = "23.00";
PArray[6] = "34.00";
PArray[7] = "39.00";
PArray[8] = "49.00";
PArray[9] = "59.00";



var MaxItems = 9;      
function cal(frm)   {
var T = 0;
var i = 0;
var cal = 0;
while (i <= MaxItems)

      { 
  	cal =  ((PArray[i] * frm.elements[i].value) );

                            T += cal;
						if( isNaN(cal) )
    				
			alert("you have not enterd a valid QTY please try again ");



  
  
  


          
		 	i = i+1;

                }

                frm.result.value = T;

      		}


    for (i = 0; i <= MaxItems; i++)

   {
      document.write("<tr align=center><td>" + CArray[i] + "</td>")
      document.write("<td><img src = '" + IMGArray[i] +   "'height='50' width='50' border='0'/></td>")
  
      document.write("<td>" + IArray[i] + "</td>")
      document.write("<td>$" + PArray[i] +  "</td>")
      document.write("<td><input type='text'  size='5' maxlength='2'/></td></tr>");
  
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.