JavaScript - Java Scanner Output Missing A Number
Hi guys,
I am new to java, I am having trouble on outputting the num2 on the screen. I could not see any errors indicated the problem on the program(Eclipse). However, the program just miss scan the num2. I was trying to sort the number and output them from smallest to largest. Any suggestion would be helpful and appreciated! ----------------------------------Code import java.util.Scanner; public class Demo{ public static void main(String[] args){ System.out.println("Please input three songs' BPMs"); int S,M,L; Scanner keyboard =new Scanner(System.in); int num1 = keyboard.nextInt(); int num2 = keyboard.nextInt(); int num3 = keyboard.nextInt(); boolean isAllSame = (num1 == num2) && (num2 == num3) && (num1 == num3); boolean isDI = (num1 != num2) && (num2 != num3) && (num1 != num3); boolean isTS = (num1 != (num2 = num3)) || ((num1=num2) !=num3) || ((num1 = num3) != num2); boolean isCMatch = Math.abs(num2 - num3) < 10 && Math.abs(num2 - num1) < 10; boolean isCM2 = Math.abs(num3 - num1) < 10 && Math.abs(num3-num2) <10; boolean isCM3 = Math.abs(num1 - num2) < 10 && Math.abs(num1-num3) <10; boolean isOkMatch = Math.abs(num2 - num3) >=10 && Math.abs(num2 - num3)<=30; boolean isOM2 = Math.abs(num3 - num1) >=10 && Math.abs(num3 - num1)<=30; boolean isOM3 = Math.abs(num1 - num2) >=10 && Math.abs(num1 - num2)<=30; boolean isMismatch = Math.abs(num2 - num3) >=31; boolean isMM2 = Math.abs(num3 - num1) >=31; boolean isMM3 = Math.abs(num1 - num2) >=31; //small to largest if (num1<num2 && num1<num3 && num2<num3){ S = num1; M =num2; L =num3;} else if (num2<num1 &&num2<num3&&num1<num3){ S = num2; M = num1; L = num3;} else if (num3<num1 &&num3<num2 && num1<num2){ S =num3; M =num1; L =num2;} else{ S = num2; M = num3; L = num1; System.out.println("Sorted BPMs a "+S +","+M +","+ L); } if (isAllSame) System.out.println("Three songs have same BPMs."); else if (isDI && isCMatch){ N(); CM(); } else if (isDI && isCM3){ N(); CM(); } else if (isDI && isCM2){ N(); CM(); } else if (isTS && isCMatch){ SBMP(); CM(); } else if (isTS && isCM2){ SBMP(); CM(); } else if (isTS && isCM3){ SBMP(); CM(); } //When two song BPM larger than 10. order from all different to two same. else if (isDI && isOkMatch){ N(); OK(); } else if (isDI && isOM3){ N(); OK(); } else if (isDI && isOM2){ N(); OK(); } else if (isTS && isOM2){ SBMP(); OK();} else if (isTS && isOM3){ SBMP(); OK();} else if (isTS && isOkMatch){ SBMP(); OK();} //When some BPMs are larger than 30, Order from all different to some are same. else if (isDI && isMismatch){ N(); PM(); } else if (isDI && isMM3){ N(); PM(); } else if (isDI && isMM2){ N(); PM(); } else if ( isTS && isMM2){ SBMP(); PM();} else if ( isTS && isMismatch){ SBMP(); PM();} else if ( isTS && isMM3){ SBMP(); PM();} } public static void SBMP(){ System.out.println("\nSome are the same BMP"); } public static void N(){ System.out.println("\nNone share the same BMP"); } public static void CM(){ System.out.println("All are within 10 BPMs of eath other");} public static void OK(){ System.out.println("All are within 10 to 30 BPMs of each other.");} public static void PM(){ System.out.println("At least two songs are Possible Match");} } ------------------------------------Output Please input three songs' BPMs 15 19 50 Sorted BPMs a 50,50,15 None share the same BMP At least two songs are Possible Match Similar TutorialsHi does anyone know how to output a reformated number to a form?? This is what I have so far: Code: if (!document.userSurvey.phone.value) { alert("Phone number missing. Please enter a valid phone number to continue."); document.userSurvey.phone.focus(); return false; } else { var numbersOnly = ""; var chars = ""; var phoneNo = document.userSurvey.phone.value; for (i = 0; i < phoneNo.length; i++) { chars = phoneNo.substring(i,i+1); if (chars >= "0" && chars <= "9") { numbersOnly = numbersOnly + chars; } } if (numbersOnly.length != 13) { alert("Incorrect phone number format.You must enter 13 numbers."); document.userSurvey.focus(); return false; } else { var areacode = numbers.substring(0,2); var leading0 = numbersOnly.substring(2,3); var exchange = numbersOnly.substring(3,5); var ext1 = numbersOnly.substring(5,9); var ext2 = numbersOnly.substring(9); var newNumber =( "+" + areacode + " " +"(" + leading0 + ")" + exchange + " " + ext1 + "-" + ext2); Need help - sorry for the novice-ness of this. Have a computed field ("Subtotal"). With that number, need to set up rule such that if Subtotal is a certain number, a certain number will print in the new field (lets call it "First"). Here's what I have so far... var a=getField("Subtotal").value; var b=5000; var c=9000; var d=33000; var e=53000; var f=68000; var g=78000; var h=83000; var i=0; Code: if (a.value<=100000){ event.value=b } else if (a.value<=200000 && a>100000){ event.value=c.value } else if (a.value<=1000000 && a>200000){ event.value=d.value } else if (a.value<=2000000 && a>1000000){ event.value=e.value } else if (a.value<=3000000 && a>2000000){ event.value=f.value } else if (a.value<=4000000 && a>3000000){ event.value=g.value } else if (a.value<=5000000 && a>4000000){ event.value=h.value } else if (a.value==0){ event.value=i.value } Any thoughts??? Help is GREATLY appreciated. D I want to Create a simple scanner app for the iPhone so when someone scans a URL embedded in a QR code, it opens the browser and loads that URL.
Hi.. I just want to know how does it happen that when I scan the barcode using barcode scanner it will automatically put on the first textbox, then the focus will go to the next textbox and on the last textbox will automatically save the data to database. here is my sample form. PHP Code: <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { echo 'failed'; die(); } mysql_select_db("mes", $con); $sr_date =date('Y-m-d H:i:s'); $sql = "SELECT sr_number FROM receiving_materials ORDER BY sr_date DESC LIMIT 1"; $result = mysql_query($sql, $con); if (!$result) { echo 'failed'; die(); } $total = mysql_num_rows($result); if ($total <= 0) { $currentSRNum = 1; $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } else { //------------------------------------------------------------------------------------------------------------------ // Stock Number iteration.... $row = mysql_fetch_assoc($result); $currentSRNum = (int)(substr($row['sr_number'],0,3)); $currentSRYear = (int)(substr($row['sr_number'],2,2)); $currentSRMonth = (int)(substr($row['sr_number'],0,2)); $currentSRNum = (int)(substr($row['sr_number'],6,4)); $currentYear = (int)(date('y')); $currentMonth = (int)(date('m')); $currentDay = (int)(date('d')); $currentSRYMD = substr($row['sr_number'], 0, 6); $currentYMD = date("ymd"); if ($currentYMD > $currentSRYMD) { $currentSRNum = 1; } else { $currentSRNum += 1; } } //------------------------------------------------------------------------------------------------------------------ $yearMonth = date('ymd'); $currentSR = $currentYMD . sprintf("%04d", $currentSRNum); ?> <html> <title>Receiving Materials</title> <head> <link rel="stylesheet" type="text/css" href="kanban.css" /> <style type="text/css"> #SR_date{ position: relative; font-family: Arial, Helvetica, sans-serif; font-size: .9em; margin-left: 10px; width: auto; height: auto; float: left; top : 10px; } </style> </head> <body> <form name="receiving_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <div id="SR_date"> <label>Date :</label> <input type="text" name="sr_date" value="<?php echo $sr_date; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="SR_number"> <label>RM# :</label> <input type="text" name="sr_number" value="<?php echo $currentSR; ?>" size="9" readonly="readonly" style="font-weight: bold; border: none;"> </div> <div id="SI_number"> <label class="LLabelRM">SI/DR# :</label> <input type="text" name="si_num" id="si_num" class="LFieldRM" value="" size="25"> <br/></br/> <label class="LLabelRM">Supplier Name :</label> <input type="text" name="s_name" id="s_name" class="LFieldRM" value="" size="25"> <br/></br/> <label class="LLabelSecRM">PO # :</label> <input type="text" name="po_num" id="po_num" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">Quantity :</label> <input type="text" name="qty" id="qty" class="LFieldSec1RM" value="" size="25"> <br/> <br/> <label class="LLabelSecRM">Material Code :</label> <input type="text" name="mat_code" id="mat_code" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">Material Desc. :</label> <input type="text" name="mat_desc" id="mat_desc" class="LFieldSec1RM" value="" size="25"> <br/></br/> <label class="LLabelSecRM">WH Code :</label> <input type="text" name="wh_code" id="wh_code" class="LFieldSecRM" value="" size="25"> <label class="LLabelSecRM">BIN Location :</label> <input type="text" name="bin_loc" id="bin_loc" class="LFieldSec1RM" value="" size="25"> </div> </form> </body> </html> Thank you I have a function below where every time a question is submitted, it will add a new row in the table with a textbox which allows numbers entry only. My question is that I don't know how to code these features in this function: 1: I want the text box to be between 0 and 100, so if text box contains a number which is above 100, it will automatically change the number to the maximum number which is 100. Does any one know how to code this in my function below in javascript: Code: function insertQuestion(form) { var row = document.createElement("tr"); var cell, input; cell = document.createElement("td"); cell.className = "weight"; input = document.createElement("input"); input.name = "weight_" + qnum; input.onkeypress = "return isNumberKey(event)"; cell.appendChild(input); row.appendChild(cell); } When I used toFixed() method on a number, I thought that this method round a number to a specified approximation, but I got a surprising result, the number became string! 15.23689 .toFixed ( 2 ) ==> "15.24" So does it convert the number into string? I am trying to figure out how to make a random number I can plug into a script count down from that number at certain times of the day until it reaches 0. I would like it to reset itself at midnight every day. I'm trying to make it work with a script I found on here that resets itself at midnight every day. So instead of it counting down too fast, it would count down to the next number after a randomly generated number of minutes until it reaches 0. But it wouldn't necessarily have to end at 0 at midnight. It could go from 845 to 323 at the end of the day at a slower pace. Is that possible?
[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. 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> 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 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> 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> 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 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 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 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! 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? 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> |