JavaScript - Why Is The Monthly Payment Missing
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" /> <title>Make10-1 Oakwood Mortgage</title> <script type="text/javascript"> <!--Hide from old browsers var thisMsg = " ** See us for your auto loan financing needs!!! ** " var beginPos =0 function scrollingMsg() { msgForm.scrollingMsg.value = thisMsg.substring(beginPos,thisMsg.length)+ thisMsg.substring(0,beginPos) beginPos=beginPos+1 if (beginPos > thisMsg.length) { beginPos=0 } window.setTimeout("scrollingMsg()",200) } function Calc(LoanCalc) { var salesAmount=parseInt(LoanCalc.SaleAmt.value,10) if (isNaN(salesAmount) || (salesAmount <= 0)) { alert("Please enter a valid Sales Amount.") LoanCalc.SaleAmt.value=" " LoanCalc.SaleAmt.focus() } else { var DownPayment=parseFloat(LoanCalc.DownPmt.value)/100 if (isNaN(DownPayment) || (DownPayment <= 0) || DownPayment > 100) { alert("The Down Payment Rate is not a valid number!") LoanCalc.DownPmt.value = "" LoanCalc.DownPmt.focus() } else { var loanRate=parseFloat(LoanCalc.Rate.value) if (isNaN(loanRate) || (loanRate <= 0)) { alert("The interest rate is not a valid number!") LoanCalc.Rate.value = " " LoanCalc.Rate.focus() } else { var loanYears = LoanCalc.Years.value var loanYears = parseInt(loanYears,10) if (isNaN(loanYears) || (loanYears == 0)) { alert("Please select the number of years from the list and click Calculate!") LoanCalc.Years.focus() } else { AmtDown = salesAmount * DownPayment var loanAmount = salesAmount - AmtDown LoanCalc.LoanAmt.value = dollarFormat(loanAmount.toFixed(2)) var monthlyPmt = monthly(loanAmount, loanRate, loanYears) LoanCalc.Payment.value = dollarformat(monthlyPmt.toString()) } } } } } function monthly(loanAmount,loanRate,loanYears) { var interestRate = loanRate/1200 var Pmts = loanYears * 12 var Amnt = loanAmount * (interestRate / (1 - (1 / Math.pow(1+interestRate,Pmts)))) return Amnt.toFixed(2) } function dollarFormat(valuein) { var formatValue = "" var formatDollars = "" formatAmt = valuein.split(".",2) var dollars = formatAmt[0] var dollarLen = dollars.length if (dollarLen > 3) { while (dollarLen > 0) { tempDollars = dollars.substring(dollarLen - 3,dollarLen) if (tempDollars.length == 3) { formatDollars = ","+tempDollars+formatDollars dollarLen = dollarLen - 3 } else { formatDollars=tempDollars+formatDollars dollarLen = 0 } } if (formatDollars.substring(0,1) == ",") dollars = formatDollars.substring(1,formatDollars.length) else dollars = formatDollars } var cents = formatAmt[1] var formatValue="$"+dollars+"."+cents return formatValue } function popUpAd() { open("make10-1notice.html","noticeWin","width=520,height=270") } function lastModified() { dateDisplay.innerHTML="<span style='font-family:Arial, Helvetica, sans-serif; font-size:9px; font-weight:bold'>This document was last modified "+document.lastModified.substring(0,10)+"</span>" } //--> </script> <style type="text/css"> <!-- body { background-image: url(financial_symbol.jpg); } --> </style> </head> <body onload="scrollingMsg(); popUpAd(); lastModified()"> <div align="center"> <p align="center"><img src="make10-1banner.jpg" width="750" height="120" alt="banner" /></p> <form id="msgForm" action=""> <p style="text-align:center"><input type="text" name="scrollingMsg" size="25" /></p> </form> </div> <div style="font-family:Arial, Helvetica, sans-serif"> <h3 align="center">Home Loan Payment Calculator</h3> <form id="LoanCalc" action=""> <table width="346" align="center" cellspacing="3"> <tr> <td align="right"> <span style="color:#cc0000">*</span>Sale Price: </td> <td><input type="text" name="SaleAmt" id="SaleAmt" size="9" /></td> </tr> <tr> <td align="right"> <span style="color:#cc0000">*</span> Down Payment as a percent </td> <td><input name="DownPmt" type="text" id="DownPmt" size="4" /> %</td> </tr> <tr> <td align="right"> <span style="color:#cc0000">*</span> Interest Rate (e.g. 5.9): </td> <td><input type="text" name="Rate" id="Rate" size="4" /> % </td> </tr> <tr> <td align="right"> <span style="color:#cc0000">*</span> Select Number of Years: </td> <td><select name="Years" id="Years"> <option selected="selected">Select Years</option> <option value="10">10</option> <option value="15">15</option> <option value="20">20</option> <option value="25">25</option> <option value="30">30</option> <option value="40">40</option> </select></td> </tr> <tr> <td align="right"> <input name="button" type="button" value="Calculate" onclick="Calc(LoanCalc)" /> </td> <td> <input name="Reset" type="reset" /> </td> </tr> <tr> <td align="right"> <span style="color:#cc0000">*</span> Loan Amount </td> <td> <input name="LoanAmt" type="text" id="LoanAmt" size="9" /> </td> </tr> <tr> <td align="right"> <span style="font-weight:bolder">Monthly Payment</span>: </td> <td><input type="text" name="Payment" id="Payment" size="12" /></td> </tr> </table> <p style="color:#cc0000; text-align:center">* Indicates a required field.</p> </form> </div> <div id="dateDisplay" style="margin-left:5%"> </div> </body> </html> Similar TutorialsHi, Im looking to make a payment form that calculates the prices as you go along, similar to this i just dont know how to go about it, is there software that can be used? thanks alot, Dan I need someone to link this: thiswebsite.com/12.html then someone clicks on a link, and the url would go to thiswebsite.com/12_1.html The link script has to subtract the ".html" from the original url, then add "_1.html" to the new url. I am pretty sure this is a simple script to make, I just do not have the time to google this and figure this out. I will pay $5 to anyone who fix this problem for me. you can post the solution here, with your paypal email so I can pay you, or email me the solution at hotgoat145@yahoo.com and tell me your paypal email so I can pay you. Im looking for a javascript code, because .htaccess does not work for me. it has to be in javascript, where it is like this <script language='JavaScript' type='text/javascript'> document.write('<a hr'+'ef="ht'+'tp://w'+'ww.mysite'+'.com/1.php">My Site</a>'); </script> Only I have to be able to subtract .php from the URL, and add _2.html to the final URL Here is what I am talking about: Go to this website: http://tehcake.com/video/30rock/2x14%20-%20Copy.html Do you see where it says Backup Links: 1 2 I need it to link to http://tehcake.com/video/30rock/2x14%20-%20Copy(2).html So it does (url of webpage [minus] file extension [plus] (2).html) it should be in javascript or something that can be written in the webpage. Hi everyone, I am converting a program that displays the payment options as a list of check boxes to a drop down list. I have tried using onBlur(), etc. but the program is displaying my error that says I didn't select a payment method. Here is the code, thanks for any hints or help! Code: <html> <head> <title>Order form</title> <meta http-equiv="Content-Type" content="text/javascript"> <script type="text/javascript"> function total() { var subtotal=0; var total=0; var adjustment=1; payment=false; var elmnts=document.payform.elements; for (var x=0; x<(document.payform.elements['item[]'].length); x++) { if (document.payform.elements['item[]'][x].checked) { subtotal=subtotal+parseFloat(document.payform.elements['item[]'][x].value); } } for (var x=0; x<(document.payform.pay.length); x++) { if (document.payform.pay[x].checked) { adjustment=document.payform.pay[x].value; payment=true; } } if (payment) { total=subtotal*adjustment; total = total.toFixed(2); document.payform.display.value="subtotal: "+subtotal+"\rAdjustment: "+adjustment+"\rTotal: "+total; } else { window.alert("Please choose payment type."); } } </script> </head> <body> <form name="payform"> <table border="0" cellpadding="5"> <tr> <td width="250" valign="top"> <b>Please buy some stuff!</b><br /> <input type="checkbox" name="item[]" value="14.99" />Chang $14.99<br /> <input type="checkbox" name="item[]" value="12.99" />Chartreuse verte $12.99<br /> <input type="checkbox" name="item[]" value="13.99" />Gnocchi di nonna Alice $13.99<br /> <input type="checkbox" name="item[]" value="14.99" />Gudbrandsdalsost $14.99<br /><br /> <b>Choose payment methods</b><br /> <select name = "pay" size = 0> <option value = "0"></option> <option value = "1.2">Monday order (20% service charge)</option> <option value = "1.1">Personal check (10% service charge)</option> <option value = ".8">Visa (preferred -- 20% discount)</option> <option value = "1.2">MasterCard (10% discount)</option> <option value = "1.2">Discover (10% discount)</option> </select> <br /><br /> <input type="button" value="Process Order" onClick="total()" /> <input type="reset" value="Reset Form" /> </td></tr> <tr> <td width="200" valign="bottom"> <textarea name="display" rows="5" cols="35"></textarea></td> </tr> </table> </form> </body> </html> [Okay, so I just wrote a simple code to try and figure out how javascript works and I can't even get this to work. What am I missing?] <html> <head> <script type="text/javascript"> var c=a+b; function displaymessage() { alert("The answer is " + c) } </script> </head> <body> <form> <p>Enter the first number <input type="text" name="a"></p> <p>Enter the second number <input type="text" name="b"></p> <input type="button" value="Enter" onclick="displaymessage()"/> </form> </body> </html> I have the following work in progress: PHP Code: var radiolist = []; var labellist = []; var rps; var tablecells = []; //function taken from JavaScripter.net which will return a hex value for the color function RGBtoHex(R,G,B) {return toHex(R)+toHex(G)+toHex(B)} function toHex(N) { if (N==null) return "00"; N=parseInt(N); if (N==0 || isNaN(N)) return "00"; N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N); return "0123456789ABCDEF".charAt((N-N%16)/16) + "0123456789ABCDEF".charAt(N%16); } //this function will add all the radio buttons to an array function getRadios(){ var inputs = document.getElementsByTagName('input'); for (i=0; i<inputs.length; i++){ if (inputs[i].type === 'radio'){ radiolist.push(inputs[i]); } } } //this function will add all labels of the "LabelWrapper" class to an array function getLabels(){ var inputs = document.getElementsByTagName('span'); for (i=0; i<inputs.length; i++){ if (inputs[i].className === 'LabelWrapper'){ labellist.push(inputs[i]); } } } getRadios(); getLabels(); //alert("There are " + radiolist.length + " radios"); //alert("There are " + labellist.length + " statements"); rps = radiolist.length / labellist.length; //alert("There are " + rps + " radios per statement") //this function will shade cells depending on their class name function identifyCells(){ var cells = document.getElementsByTagName('td'); for (i=0; i<cells.length; i++){ for (j=3; j<(rps+4); j++){ var tclass = "c" + j; if ((cells[i].className === tclass + " ") || (cells[i].className === tclass + " last ")){ xred = Math.round((j-2) * 255/(rps)); xblue = Math.round((j-2) * 255/(rps) - 50); xgreen = Math.round(50 + (rps-j+4) * 255/(rps)); xcolor = "#" + RGBtoHex(xred,xgreen,xblue); cells[i].setAttribute('col',xcolor); cells[i].addEventListener('mouseover',highlightCells,false); cells[i].addEventListener('mouseout',clearHighlights,false); } } } } } //this function will highlight all preceding cells in the same row function highlightCells(){ var y = this.getAttribute('col'); var z0 = this.className.split("c"); //split the classname in two so that we can use parseInt function var z = parseInt(z0[1]); this.style.backgroundColor = y; var cellfamily = this.parentNode.childNodes; for (i=0; i<cellfamily.length; i++){ cellname = cellfamily[i].className.split("c"); cellnum = parseInt(cellname[1]); if (cellnum > 3 && cellnum < z){ cellfamily[i].style.backgroundColor = y; } } } function clearHighlights(){ var z0 = this.className.split("c"); var z = parseInt(z0[1]); this.style.backgroundColor = "transparent"; var cellfamily = this.parentNode.childNodes; for (i=0; i<cellfamily.length; i++){ cellfamily[i].style.backgroundColor = "transparent"; } } identifyCells(); FireFox is giving me the "missing ) after argument list" at the following line: function highlightCells(){ I can't figure out why I am getting an error. The code was 'working' before and I was able to get the highlighting on the table cells, but I don't know what I did that caused the issue. Any help would be greatly appreciated. what is wrong with this Code: function addfavorites(classid,userid) { // alert("here"); var urltoajax = "addfavorites.php?j=1&classid="+ classid + "&userid="+ userid; urltoajax = urltoajax + '&rnd=' + Math.round(Math.random() * 10000) alert(urltoajax); $.ajax({ url: urltoajax, cache: false, success: function(html) { $("#message").html(html); } }); //alert('here 2'); } i get an error Object doesn't support this property or method I am trying to run this script on my small form and I cannot seem to get very far - the error console keeps saying I am missing a ; before statement and then the green arrows points to the f in var formValid==true; ?? Is anyone able to help here asI can not see why ??? below is my small script.... Thank you <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Error checking</title> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" /> <script type="text/javascript"> function checkForm(theform){ var formValid==true; var elementCount=0; while(elementCount<theform.elements.length) // returns the total number of form elements within the form { if (theform.elements[elementCount].type=="text")//returns the type of the elementCount form element (ie:"textarea") { if (theform.elements[elementCount].value=="") alert("Please complete all form elements") theform.elements[elementCount].focus(); formValid=false; break; } elementCount++; } return formValid; } </script> </head> <body> Hi ... i am trying to run my website but when i am accessing through the link....i am getting missing ) after argument list .it showing the following peace of code in the firebug.... missing ) after argument list else{$("input[id^=channelPid_]")\n can anyone help me to resolve this issues..its been three days i am working on it but no clue... thanks in advance This code is from a No Redirect Bookmarklet used with Firefox. The code works great as a bookmarklet but fails when used in a button code like this: loadURI("Bookmarklet Code Here"); When I evaluate it using JavaScript Command I get an error popup window stating "SyntaxError: missing variable name" I assume it is caused by this part: vark,x,t,i,j,p; How can I eliminate the error? No Redirect Bookmarklet Code: javascriptfunction(){var%20k,x,t,i,j,p;%20for(k=0;x=document.links[k];k++){t=x.href.replace(/[%]3A/ig,':').replace(/[%]2f/ig,'/');i=t.lastIndexOf('http');if(i>0){%20t=t.substring(i);%20j=t.indexOf('&');%20if(j>0)t=t.substring(0 ,j);%20p=/https?\:\/\/[^\s]*[^.,;'%22>\s\)\]]/.exec(unescape(t));%20if(p)%20x.href=p[0];%20}%20else%20if%20(x.onmouseover&&x.onmouseout){x.onmouseover();%20if%20(window.status%20&&%20wind ow.status.indexOf('://')!=-1)x.href=window.status;%20x.onmouseout();%20}%20x.onmouseover=null;%20x.onmouseout=null;%20}})(); No Redirect Bookmarklet Code with Break and Spaces: javascriptfunction(){ vark,x,t,i,j,p; for(k=0; x=document.links[k]; k++){ t=x.href.replace(/[%]3A/ig,':').replace(/[%]2f/ig,'/'); i=t.lastIndexOf('http'); if(i>0){ t=t.substring(i); j=t.indexOf('&'); if(j>0)t=t.substring(0,j); p=/https?\:\/\/[^\s]*[^.,; '%22>\s\)\]]/.exec(unescape(t)); if(p)x.href=p[0]; } elseif(x.onmouseover&&x.onmouseout){ x.onmouseover(); if(window.status&&window.status.indexOf('://')!=-1)x.href=window.status; x.onmouseout(); } x.onmouseover=null; x.onmouseout=null; } } )(); I would appreciate any help offered. I don't know much about JavaScript coding including how to indent properly. Where could I find out how to indent properly? Hi folks! What's wrong with this? PHP Code: var addWpParams = { 'code' : item.code, 'name' : item.name, 'type' : item.type, 'lat' : item.lat, 'lng' : item.lng, 'latLng' : latLng }; addWpParams(addWpParams); Returns an error: "missing ] after element list" in firebug I must be doing something wrong but what? TIA Hello all - I am new to JS and figure this is probably an easy fix. I have a wordpress self-hosted site. I am doing a nav bar with rollovers. I have the script saved as a js file and in the right directory. I have the Code: <script src="<?php bloginfo('template_directory'); ?>/js/menu.js" type="text/javascript"></script> in the header.php file just after the body tag. I have the styles where I want them in the CSS file. And lastly I have the html and the appropriate wordpress php call in the right spot. The css is working fine, which leads me to believe my css and html are spot on. But there is no rollover working. Do I need to put anything besides styling into my css file? Any help is much appreciated. Thanks. hi friends , i am on make a dynamic input field creation code , my problem is the entered text(value from "add proposition") is washing away , if i press new "add proposition" my java script is PHP Code: <script language="javascript" type="text/javascript"> function add() { k=document.getElementById("num").innerHTML k=parseInt(k); if(!k) {document.getElementById("num").innerHTML=1; k=1;} else{ document.getElementById("num").innerHTML=k+1; k++; } document.getElementById("cat").innerHTML+="<br />type propositon "+(k)+":<input type=\"text\" name=\"prop"+k+"\">is it answer? <input type=\"checkbox\" name=\"ans"+k+"\"> ignore this one:<input type=\"checkbox\" name=\"ign"+k+"\">" } </script> my html code is PHP Code: <form action="new.php" method="post"> <fieldset> <legend>Add Question & answer:</legend> question type:<br /> True or False:<input type="radio" name="radio" value="t"> Objective:<input type="radio" name="radio" value="o"> Other:<input type="radio" name="radio" value="o"> Quesion:<br /> <textarea name="desc" rows="6" cols="35" ></textarea> <br /> <a href="javascript:add()" ><b>add proposition</b></a> <div id="cat"></div> <div id="num" style="display:none;"></div> <br> <input type="submit" name="submit"> </fieldset> </form> how i solve this problem ? I can't seem to shake this error message. Here is the code I am working with PHP Code: <tr> <td> <img onClick="showUser(1,\''.$time.'\');" src="'.$this->getPhoto($array[0][1]['uid'],'').'" > </td> <td> <img onClick="showUser(2,\''.$time.'\');" src="'.$this->getPhoto($array[0][2]['uid'],'').'" > </td> <td> <img onClick="showUser(3,\''.$time.'\');" src="'.$this->getPhoto($array[0][3]['uid'],'').'" > </td> <td> <img onClick="showUser(4,\''.$time.'\');" src="'.$this->getPhoto($array[0][4]['uid'],'').'" > </td> and the function PHP Code: '.$this->get_javascript_array($this->data,'data').' function showUser(arr, time) { var likes; var comments; switch(time) { case "Day": likes = data['day\'][0][arr][\'likes\']); comments = data[\'day\'][0][arr][\'comments\']); break; case "Week": likes = data[\'week\'][0][arr][\'likes\']); comments = data[\'week\'][0][arr][\'comments\']); break; case "Month": likes = data[\'month\'][0][arr][\'likes\']); comments = data[\'month\'][0][arr][\'comments\']); break; case "Year": likes = data[\'year\'][0][arr][\'likes\']); comments = data[\'year\'][0][arr][\'comments\']); break; } }; </script> '; I keep getting the following error and it's driving me nuts PHP Code: missing ; before statement [Break on this error] likes = data['day'][0][arr]['likes']);n Why does this not work? Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> function printtext(){ document.write("Hello"); } </script> </head> <body> <input type="button" value="click me" onclick="printtext()" /> </body> </html> I get my button and when I click it the page reloads but I get no "hello". Sorry in advance, this is probably a dumb question! For some reason I run my script and its saying missing } after property list. But I'm not seeing it. Code: <script type="text/javascript"> $(document).ready(function() { $('div.message-error').hide(); $('div.message-success').hide(); $('ul#characterList').css( 'margin-left', '120px' ); $('li').remove('.characterName'); $("#handlerForm").validate({ rules: { firstName: "required", lastName: "required", userName: { required: true, minlength: 2 }, password: { required: true, minlength: 5 }, password2: { required: true, minlength: 5, equalTo: "#password" }, email: { required: true, email: true }, messages: { firstName: "Please enter your firstname", lastName: "Please enter your lastname", userName: { required: "Please enter a username", minlength: "Your username must consist of at least 2 characters" }, password: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long" }, password2: { required: "Please provide a password", minlength: "Your password must be at least 5 characters long", equalTo: "Please enter the same password as above" }, email: "Please enter a valid email address" } }); $("input.submit").click(function() { var userID = $("input#userID").val(); var defaultChar = $("select#charactersDrop option:selected").text(); var userName = $("input#userName").val(); var firstName = $("input#firstName").val(); var lastName = $("input#lastName").val(); var email = $("input#email").val(); var statusID = $("select#statusID").val(); var isAdmin = $("select#isAdmin").val(); var liElements = $("ul#characterList li"); var characterIDList = ""; for( var i = 0; i < liElements.length; i++ ) { var liElement = $( liElements[ i ] ); // only start appending commas in after the first characterID if( i > 0 ) { characterIDList += ","; } // append the current li element's characterID to the list characterIDList += liElement.data( 'characterID' ); } var dataString = 'userID=' + userID + 'userName=' + userName + '&password=' + password + '&firstName=' + firstName + '&lastName=' + lastName + '&email=' + email + '&statusID=' + statusID + '&isAdmin=' + isAdmin + '&characterIDList=' + characterIDList + '&submitHandler=True'; $.ajax({ type: "POST", url: "processes/handler.php", data: dataString, success: function(myNewVar) { if (myNewVar == 'good') { $('div.message-error').hide(); $("div.message-success").html("<h6>Operation successful</h6><p>" + userName + " saved successfully.</p>"); $("div.message-success").show().delay(10000).hide("slow"); $(':input','#handlerForm') .not(':submit, :button, :hidden') .val('') $('ul#characterList li').each(function() { $(this).remove(); }); } else if (myNewVar == 'bad1') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + userName + " already exists in the database.</p>"); $("div.message-error").show(); } else if (myNewVar == 'bad2') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + email + " already exists in the database.</p>"); $("div.message-error").show(); } else if (myNewVar == 'bad3') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + userName + " and " + email + " already exists in the database.</p>"); $("div.message-error").show(); } else if (myNewVar == 'bad1bad2') { $('div.message-success').hide(); $("div.message-error").html("<h6>Operation unsuccessful</h6><p>" + userName + " and " + email + " already exists in the database.</p>"); $("div.message-error").show(); } } }); return false; }); }); </script> <!-- Form --> <form action="#" id="handlerForm"> <fieldset> <legend>Add New Handler</legend> <div class="field required"> <label for="userName">User Name</label> <input type="text" class="text" name="userName" id="userName" title="User Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="password">Password</label> <input type="password" class="text" name="password" id="password" title="Password" /> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="password2">Confirm Password</label> <input type="password" class="text" name="password2" id="password2" title="Confirm Password" /> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="firstName">First Name</label> <input type="text" class="text" name="firstName" id="firstName" title="First Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="lastName">Last Name</label> <input type="text" class="text" name="lastName" id="lastName" title="Last Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="email">Email</label> <input type="text" class="text" name="email" id="email" title="Email"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="statusID">Status</label> <select class="dropdown" name="statusID" id="statusID" title="Status"> <option value="0">- Select -</option> <?php $query = 'SELECT ID, statusName FROM statuses'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['statusName']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="isAdmin">Administrator</label> <select class="dropdown" name="isAdmin" id="isAdmin" title="Administrator"> <option value="0">- Select -</option> <?php $administrator = array('Yes', 'No'); foreach($administrator as $admin): ?> <option value="<?php echo $admin; ?>"><?php echo $admin; ?></option> <?php endforeach; ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> </fieldset> <fieldset> <legend>Handler's Characters</legend> <div class="field"> <label for="charactersDrop">Characters</label> <select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Dropdown"> <option value="0">- Select -</option> <?php $query = 'SELECT ID, characterName FROM characters WHERE ID NOT IN (SELECT characterID FROM handlerCharacters) ORDER BY `characterName`'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r"; } ?> </select> <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/> <ul id="characterList"></ul> </div> <input type="hidden" name="userID" id="userID" value="<?php echo $userID; ?>" /> <input type="submit" class="submit" name="submitHandler" id="submitHandler" title="Submit Handler" value="Submit Handler" /> </fieldset> </form> <!-- /Form --> <!-- Messages --> <div class="message message-error"> <h6>Required field missing</h6> <p>Please fill in all required fields. </p> </div> <div class="message message-success"> <h6>Operation succesful</h6> <p>Handler was added to the database.</p> </div> <!-- /Messages --> <script type="text/javascript" language="javascript"> // Long version function HandlerCharacters() { function isDupe(which) { var result = false; $('ul#characterList li').each(function(i, e) { if ($(e).data('characterID') == which) { result = true; return false; // break out of .each() } }); return result; } var characterID = $('#charactersDrop option:selected').val(); var characterName = $('#charactersDrop option:selected').text(); if (characterID > 0 && !isDupe(characterID)) { // Create the anchor element var anchor = $( '<a href="#">Remove</a>' ); // Create a click handler for the anchor element anchor.click( function() { $( this ).parent().remove(); return false; // makes the href in the anchor tag ignored } ); // Create the <li> element with its text, and then append the anchor inside it. var li = $( '<li>' + characterName + ' </li>' ).append( anchor ); li.data( 'characterID', characterID ); // Append the new <li> element to the <ul> element $( '#characterList' ).append( li ); } } </script> I just started learning JavaScript. I'm sure it's something really simple but I cannot figure out what is missing from my code. No matter what year I enter into the text box, I keep getting "The year you entered, 2080393, is a leap year." It's not returning false...ever. Can someone please tell me what I'm doing wrong so I can stop pulling my hair out? Thanks! <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>Is It A Leap Year?</title> <script type="text/javascript"> /* <![CDATA[ */ function isLeapYear(year) { year = parseInt(year); var leapYear = true; var remainder = 0; if(isDivisibleBy(year, 4)) { leapYear = true; } if(isDivisibleBy(year, 100)) { leapYear = false; } if(isDivisibleBy(year, 400)) { leapYear = true; } if(leapYear) { window.alert("The year you entered, " + year + ", is a leap year."); } else { window.alert("The year you entered, " + year + ", is not a leap year."); } } function isDivisibleBy(year, divisor) { var remainder = 0; remainder = year%divisor; if(remainder == 0) { return true; } else { return false; } } /* ]]> */ </script> </head> <body> <form action="" id="GetLeapYear"> <p><strong>Is It a Leap Year?</strong></p> <p><strong>Enter a valid 4-digit year below to find out!</strong><br /></p> <p> <input type="text" name="year" size="20" style="color: black; border-style: solid; border-color: inherit; border-width: medium; background-color: Transparent" value="" /> <input type="button" value="Leap Year?" onclick="isLeapYear(document.getElementById('GetLeapYear').year.value);" /> </p> </form> </body> Hey all, I have a script below, which I hope will generate query strings passed back to server using ajax depending on whether user selects an option from dropdown or enters content in a text field. Nevertheless, the issue I'm having at the moment is the firebug error: missing : after property id drop-filter: {\n It's telling me something is syntactically wrong with the drop-filter constructed in object notation below. But to me it looks correct: Code: <script> (function($){ var listview = $('#listview'); var lists = (function(){ var criteria = { drop-filter: { insert: function(value){ if(value) return handleFilter("filter", value); }, msg: "Filtering..." }, search-filter: { insert: function(value){ if(value) return handleFilter("search", value); }, msg: "Searching..." } } var handleFilter = function(key,value){ return {key: value}; } return { create: function(component){ var component = component.href.substring(component.href.lastIndexOf('#') + 1); return component; }, setDefaults: function(component){ var parameter = {}; switch(component){ case "sites": parameter = { 'order': 'site_num', 'per_page': '20', 'url': '/sites' } } return parameter; }, getCriteria: function(criterion){ return criteria[criterion]; }, addCriteria: function(criterion, method){ criteria[criterion] = method; } } })(); var Form = function(form){ var fields = []; $(form[0].elements).each(function(){ var field = $(this); if(typeof field.attr('alter-data') !== 'undefined') fields.push(new Field(field)); }) } Form.prototype = { initiate: function(){ for(field in this.fields){ this.fields[field].calculate(); // THIS DOESN"T MAKE SENSE WHY WE CALL CALCULATE HERE WHEN WE DIDN"T EVEN CALL ATTACH YET AND HENCE DONT KNOW WHAT TYPE OF EVENT TO RESPOND TO } }, isCalculable: function(){ for(field in this.fields){ if(!this.fields[field].alterData){ return false; } } return true; } } var Field = function(field){ this.field = field; this.alterData = false; this.attach("change"); this.attach("keyup"); } Field.prototype = { attach: function(event){ var obj = this; if(event == "change"){ obj.field.bind("change", function(){ return obj.calculate(); }) } if(event == "keyup"){ obj.field.bind("keyup", function(e){ return obj.calculate(); }) } }, calculate: function(){ var obj = this, field = obj.field, msgClass = "msgClass", msgList = $(document.createElement("ul")).addClass("msgClass"), types = field.attr("alter-data").split(" "), container = field.parent(), messages = []; field.next(".msgClass").remove(); for(var type in types){ var criterion = lists.getCriteria(types[type]); if(field.val()){ var result = criterion.insert(field.val()); container.addClass("waitingMsg"); messages.push(criterion.msg); obj.alterData = true; initializeTable(result); } else { return false; obj.alterData = false; } } if(messages.length){ for(msg in messages){ msgList.append("<li>" + messages[msg] + "</li"); } } else{ msgList.remove(); } } } $('#dashboard a').click(function(){ var currentComponent = lists.create(this); var defaults = lists.setDefaults(currentComponent); initializeTable(defaults); }); var initializeTable = function(custom){ var defaults = {} var custom = custom || {}; var query_string = $.extend(defaults, custom); var params = []; $.each(query_string, function(key,value){ params += key + ': ' + value; }) $.ajax({ type: 'GET', url: '/' + url, data: params, dataType: 'html', error: function(){}, beforeSend: function(){}, complete: function() {}, success: function(response) { listview.html(response); } }) } $.extend($.fn, { calculation: function(){ var formReady = new Form($(this)); if(formReady.isCalculable) { formReady.initiate(); } }) var form = $(listview + ' fieldset'); form.calculation(); })(jQuery) </script> Thanks for response. Code: this.delete = function(obj) { .. Is that it ? I can't have delete ? Or can this be written in some other way, including delete ? This is straight out of an O'Riley book, everything looks good to me but for some reason the script does nothing when I try to submit an empty form. Code: // Validate Registration Form function validate(form) { fail = validateUsername (form.uname.value) fail += validateUpass (form.upass.value) fail += validatePassword (form.password.value) fail += validateFname (form.fname.value) fail += validateLname (form.lname.value) fail += validateID (form.ID.value) fail += validateEmail (form.email.value) if (fail =="") return true else {alert(fail); return false } } function validateUsername (field) { if (value==null||value=="") return "Please enter username.\n" return "" } function validateUpass (field) { if (field =="") return "Please enter password.\n" return "" } function validatePassword (field) { if (value == "") return "Please confirm password. \n" return "" } function validateFname (field) { if (value =="") return "Please enter a first name.\n" return"" } function validateLname (field) { if (value=="") return "Please enter a last name.\n" return"" } function validateID (field) { if (value=="") return "Please enter your USAC license number.\n" return "" } function validateEmail (field) { if (value=="") return "Please enter your email address.\n" else if (!((field.indexof(".")>0) && (field.indexOf("@") > 0)) || /[^a-zA-Z0-9.@_-]/.test(field)) return "The Email address is invalid.\n" return"" } Code: <script src="includes/js/validate-registration-form.js"></script> </head> <body> <div id="wrap"> <h1>CritTracker.com Registration page</h1> <?php include('includes/nav.php');?> <div id="content_wrap"> <div id="center_content"> <div id="register"> <form class="register" method="post" action="register.php" onSubmit="return validate(this)"> <fieldset> <legend>Register to CritTracker</legend> <ol> <li> <label for="uname">Username</label> <input type="text" name="uname" /><br /> </li> <li> <label for="upass">Password</label> <input type="password" name="upass" /><br /> </li> <li> <label for="upass">Confirm Password</label> <input type="password" /><br /> </li> <li> <label for="fname">First Name</label> <input type="text" name="fname" /><br /> </li> <li> <label for="lname">Last Name</label> <input type="text" name="lname" /><br /> </li> <li> <label for="ID">USA Cycling License</label> <input type="text" name="ID" /> <select name="cat"> <option name="cat" value="5">Cat 5</option> <option name="cat" value="4">Cat 4</option> <option name="cat" value="3">Cat 3</option> <option name="cat" value="2">Cat 2</option> <option name="cat" value="1">Cat 1</option> </select> </li> <li> <label for="email">Email</label> <input type="text" name="email" /><br /> <input type="submit" value="Register to CritTracker.com" /> </li> </ol> </fieldset> </form> </div></div> I have added an image rotator to my website using Java Script. The box for the rotator shows up on the published site but not the pictures. When I click on the box it links to the pictures I have added, and I know they are rotating because it changes every time I click on it. Also, the code does not seem to be showing up when I view the source of the page. This is a link to my site: http://www.jenniferbrenn.com/Fashion/Home.html the problem is in the box beneath the name "Jenny" near the bottom of the page. This is the code I am using: [CODE] <script language="JavaScript"> // Copyright 1996, Infohiway, Inc. (http://www.infohiway.com) // Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/ <!-- function adArray() { for (i=0; i*2<adArray.arguments.length; i++) { this[i] = new Object(); this[i].src = adArray.arguments[i*2]; this[i].href = adArray.arguments[i*2+1]; } this.length = i; } function getAdNum() { dat = new Date(); dat = (dat.getTime()+"").charAt(8); if (dat.length == 1) ad_num = dat%ads.length; else ad_num = 0; return ad_num; } var ads = new adArray( "images/banner_1.gif","http://web.me.com/jim.stevenson/Fashion/Media/bee_vogue.jpg", "images/banner_2.gif","http://www.superficialdiva.com/wp-content/uploads/2009/01/hana-soukupova-vogue-belleza-february-2009-magazine-cover.jpg", "images/banner_3.gif","http://bp3.blogger.com/_maRo3z-KVqA/R9IKSDQPIwI/AAAAAAAAB4g/ghZysBSq-9M/s400/Victoria-Beckham-Vogue.jpg"); var ad_num = getAdNum(); document.write('<CENTER><TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0><TR><TD ' +'ALIGN=CENTER><FONT SIZE=2 FACE=Arial><B>Jenny ' +'</FONT></TD><TR></TR><TD><A HREF="'+ads[ad_num].href+'"><IMG SRC="'+ads[ad_num].src+'" ' +'WIDTH="240" HEIGHT="320" BORDER=0 name=js_ad></A></TD></TR></TABLE></CENTER>'); link_num = document.links.length-1; function rotateSponsor() { if (document.images) { ad_num = (ad_num+1)%ads.length; document.js_ad.src = ads[ad_num].src; document.links[link_num].href = ads[ad_num].href; setTimeout("rotateSponsor()",5000); } } setTimeout("rotateSponsor()",5000); // --> </script> [CODE] |