• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

JavaScript Problem

Status
Not open for further replies.
Level 9
Joined
Dec 25, 2008
Messages
110
I want to build a javascript scenario that will validate the given data from an html form and then , if they are correct, create a window that says the purchase (since the page is that of a supposed e-shop) is complete , shows the product and then shows the amount , creditcard number, and credit card type as well as the full price.

The thing is that when I test my scenario on Firefox, it will either freeze or refuse to execute it.:goblin_wtf: Anyone have any ideas why?
Code below(the problematic one is the code within the <head> tag):
Edit: Something is messed up from if (am > 100 ) and on till the end of the script , and it doesn't show darkblue letters anymore.Hope this is not my error in coding.


HTML:
<head>
     <title>Game of Thrones:Genesis</title>
	 <link rel="stylesheet" href="MainpageCss.css" />
	 <link rel="shortcut icon" href="3-thing.ico" />
	 <script type="text/javascript">
<!--
	     /*Javascript code so I can keep the values where I want them*/
	     /* Contents needed:
	     3. The amount one wishes to buy
	     4. The credit card number of the buyer
	     I will try to make a script to check them all and to execute some functions if these things are correct, else
	     to alert the user of it*/
		 //Below we create the window for the confirmation and completion of purchase
	     function CreateWin(cctype, am, cn) {
	         var contents = "<html><body bgcolor='#445566'><h1 style='font-family: Calibri;'>You have requested to buy: <font color=\"#55FF44\">Game of Thrones: Genesis</font> " + " <br/><hr/>which costs:<font color=\"#55FF44\"> 39.99</font>" + "&euro; per unit bought<br/><hr/> and at amount: <font color=\"#55FF44\">" + am + "</font><br/><hr/>via <font color=\"#55FF44\">" + cctype + "</font><br/><hr/> with credit card number: <font color=\"#55FF44\">" + cn + "</font><br/><hr/>" + "Total Price is: <font color=\"#55FF44\">" + (am * 39.99) + "</font> &euro;<br/>" + "Your item will be delivered to you in a few days" + "<br/>" + "<input type=\"button\" value=\"Close\" onClick=\"javascript:window.close()\"  style=\"width: 192px\"/>" + "</h1>" + "</body>" + "</html>";
	         var options = "toolbar=0,status=0,scrollbars=1,resizable=1,width=600, height=385,menubar=no";
	         //Here we open the window using these options and contents
	         win = window.open("", "purchasewindow", options);
	         win.document.write(contents);
	         win.document.close();
	     }
		 function Validate(am, ccnum) {
	         //Here we validate the given data
	         //Name of Product is already given by the developer (myself) and so is skipped
	         //Still it is needed so it can be passed from one function to another.
	         //Price of Product is also skipped for the same reasons
	         var Temp = document.getElementById("Visa").checked;
	         var CCtype = "";
	         if (Temp == true) {
	             CCtype = "Visa";
	         }
	         else if (Temp == false) {
	             Temp = document.getElementById("Mastercard").checked;
	             if (Temp == true) {
	                 CCtype = "Mastercard";
	             }
	             else {
	                 alert("You must select a credit card type");
	             }
	         }
	         //Amount check
	         if ((isNaN(am) == true) || (am == 0)) {
	             alert("Amount is invalid.");
	         }
	         if (am > 100) {
	             alert("Amount number overflow.Please choose a lower number.");
	         }
	         //Credit Card Number check
	         if ((ccnum.length != 16) || (isNaN(ccnum) == true)) {
	             alert("Your given credit card number is invalid.");
	         }
	         if ((ccnum.length == 16) && (isNaN(ccnum)==false) && (!((isNaN(am) == true) || (am == 0))) && (CCtype!="")) {
	             //Means everything is correct
	             CreateWin(CCtype, am, ccnum);
	         }
	     }
	     function LoadData() {
	         var Amount = document.getElementById("Amount").value;
	         var CreditCard = document.getElementById("CCNum").value;
	         Validate(Amount, CreditCard);
	     }
//-->
</script>
</head>
<body text="red">
     <div id="sitename">G    A    M    E    H    I    V    E  - All pc games in one spot.</div>
     <br/>
     <table>
         <tr>
             <td><a href="GameHiveMain.html">H o m e</a>  ||</td>
	         <td><a href="GameReleases.html">R e l e a s e d  G a m e s</a>  ||</td>
	         <td><a href="NGameReleases.html">2 0 1 2  R e l e a s e s</a>  ||</td>
	         <td><a href="mailto:FFFFFFFF.com?subject=Registration Request">R e g i s t e r</a>   ||</td>
	         <td>     Need             </td>
	         <td>     any              </td>
	         <td>     help?            </td>
	         <td><a href="Help.html">H e l p</a></td>
         </tr>
     </table>
	 <br/>
	 <br/>
	 <table>
		     <tr>
			     <td><a href="GotGenesisGr.html">Greek</a></td>
			 </tr>
			 <tr>
			     <td>English</td>
			 </tr>
		 </table>
	 <br/>
	 <br/>
	 	 <div class="comment"> You are now at:</div>
		 <span><a href="GameHiveMain.html">Gamehive's Main Page</a>&nbsp;-><a href="GameReleases.html">Released Games</a>&nbsp;-><span class="comment">Game of Thrones:Genesis</span></span>
     <h1>G A M E   O F    T H R O N E S   :    G E N E S I S</h1>
	 <ul>
	     <li><div class="comment">Game type: Strategy, with a heavy political decision-making involved</div></li>
		 <li>Status:<font color="green" style="font-size: 15pt;">Released</font></li>
		 <li>Trailer</li>
		 <li><iframe width="560" height="315" src="http://www.youtube.com/embed/c3LPwUJOW4o" frameborder="0" allowfullscreen></iframe></li>
         <li><div class="comment">Price:<div style="background-color: #332211">39.99 &euro;</div></div></li>
		 <li><div class="formchar">In order to purchase this item, you must fill in the following form with your <b>real</b> information</div></li>
			 <li><form action="GotGenesis.html" onsubmit="LoadData()"><!-- Source of the problem -->
             <div class="formchar">Product Name:</div><input type="text" id="Product" value="Game of Thrones: Genesis" readonly="readonly" style="background-color: Black; color:Blue; border-color: #332211;" />
             <div class="formchar">Price:</div><input type="text" id="Price" value="39.99" readonly="readonly" style="background-color: Black; color:Blue; border-color: #332211;" /> &euro;
             <div class="formchar">Amount:</div><input type="text" name="Amount" /><br />
             <div class="formchar">Credit Card type:</div><br/>
			 <div class="formchar">Visa</div><input type="radio" name="cctype" id="Visa"/><br/>
			 <div class="formchar">Mastercard</div><input type="radio" name="cctype" id="Mastercard"/><br/>
             <div class="formchar">Credit Card Number:</div><input type="text" name="CCNum" />
			 <input type="submit" value="Submit"/>&nbsp;<input type="reset" value="Reset Data" />&nbsp;
             </form></li>
	 </ul>
	 <br/>
	 <br/>
	 <br/>
	 <br/>
	 		 <div class="tchars" align="right">Jump to:<br/>
			 <select name="formal" onchange="javascript:handleSelect(this)"> 
				 <option value="GameHiveMain">Home</option> 
				 <option value="NGameReleases">New Game Releases</option>
				 <option value="GameReleases">Released Games</option>
				 <option value="NLL">/============================================/</option>
				 <option value="NLL">/============Released Games==================/</option>
				 <option value="SWOldRepublic">Star Wars:Old Republic</option>
				 <option value="GotGenesis">Game of Thrones:Genesis</option>
				 <option value="TheWitcher">The Witcher</option>
				 <option value="StarcraftIIWoL">Starcraft II:Wings of Liberty</option>
				 <option value="DragonAgeII">Dragon Age II</option>
				 <option value="NLL">/============================================/</option>
				 <option value="NLL">/=========New Releases=======================/</option>
				 <option value="DiablII">Diablo III</option>
				 <option value="StarcraftIIHoTS">Starcraft II:Heart of the Swarm</option>
				 <option value="NLL">/============================================/</option>
				 <option value="NLL">/=========Help===============================/</option>
				 <option value="Help">Help</option>
			 </select>
		 </div>
<script type="text/javascript">
<!--
function handleSelect(elm) {
    if (elm.value != "NLL") {
        window.location = elm.value + ".html";
    }
    else {
    }
}
//-->
</script>
</body>
</html>
Edit: I found the source of the problem.Nevertheless I shall leave the code above untouched.
 
Last edited:
Status
Not open for further replies.
Top