Search Results

Search found 461 results on 19 pages for 'parseint'.

Page 10/19 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • javascript literal initialisation loop

    - by graham.reeds
    I have an object which has several properties that are set when the object is created. This object recently changed to object literal notation, but I've hit a bit of a problem that searching on the net doesn't reveal. Simply stated I need to do this: Star = function(_id, _x, _y, _n, _o, _im, _c, _b, _links) { var self = { id: _id, // other properties links: [], for (var i=0,j=0;i<8;i++) { //<- doesn't like this line var k = parseInt(_links[i]); if (k > 0) { this.links[j++] = k; } }, // other methods }; return self; }; How do I initialise a property in the constructor in object literal notation?

    Read the article

  • Looping through list items with jquery

    - by Gallen
    I have this block of code listItems = $("#productList").find("li"); for (var li in listItems) { var product = $(li); var productid = product.children(".productId").val(); var productPrice = product.find(".productPrice").val(); var productMSRP = product.find(".productMSRP").val(); totalItemsHidden.val(parseInt(totalItemsHidden.val(), 10) + 1); subtotalHidden.val(parseFloat(subtotalHidden.val()) + parseFloat(productMSRP)); savingsHidden.val(parseFloat(savingsHidden.val()) + parseFloat(productMSRP - productPrice)); totalHidden.val(parseFloat(totalHidden.val()) + parseFloat(productPrice)); } and I'm not getting the desired results - totalItems is coming out as 180+ and the rest all NaN. I suspect its where i use var product = $(li); or perhaps with the expression on the loop itself. Either way - I need to loop through the <li> items in the <ul> labelled #productList

    Read the article

  • Sorting an arraylist in Java language

    - by Computeristic
    Hi, I have an arraylist set up. I have input instuctions set up too, so that the user can enter one string, then one integer, then one string (the first name, the age, and the last name). I need to sort the arraylist by the last name. The code I have entered so far is all under the main method:- public static void main(String[] args) { Name Name[] = new Name[50]; int count = 0; for (int i=0; i<50; i++) NewName[i] = new Name(); //ADD NEW TO ARRAYLIST NAME String FName = JOptionPane.showInputDialog("first name"); int age = Integer.parseInt(JOptionPane.showInputDialog("age")); String LName = JOptionPane.showInputDialog("last name"); NewName[count] = new Name(FName, age, LName); count = count++; } //ITEMS SORT BY LAST NAME //CODE FOR SORT GOES HERE

    Read the article

  • Javascript : assign variable in if condition statement, good practice or not?

    - by Michael Mao
    Hi all: I moved one years ago from classic OO languages such like Java to Javascript. The following code is definitely not recommended (or even not correct) in Java: if(dayNumber = getClickedDayNumber(dayInfo)) { alert("day number found"); } function getClickedDayNumber(dayInfo) { dayNumber = dayInfo.indexOf("fc-day"); if(dayNumber != -1) //substring found { //normally any calendar month consists of "40" days, so this will definitely pick up its day number. return parseInt(dayInfo.substring(dayNumber+6, dayNumber+8)); } else return false; } Basically I just found out that I can assign a variable to a value in an if condition statement, and immediately check the assigned value as if it is boolean. For a safer bet, I usually separate that into two lines of code, assign first then check the variable, but now that I found this, I am just wondering whether is it good practice or not in the eyes of experienced javascript developers? Many thanks in advance.

    Read the article

  • How can I replace only the last occurence of an number in a string with php?

    - by Shawn
    How would you change this: a-10-b-19-c into something like this: a-10-b-20-c using regular expressions in PHP? The only solution I've found so far is: reverse the original string - "c-91-b-01-a" find the first number - "91" reverse it - "19" turn in into a number (parseInt) - 19 add 1 to it (+1) - 20 turn it into a string again (toString) - "20" reverse it again - "02" replace the original match with this new number - "c-02-b-01-a" reverse the string - "a-10-b-20-c" I was hoping someone on SO would have a simpler way to do this... Anyone?

    Read the article

  • user agent checking for ios6

    - by Akash Saikia
    I am trying to check whether client opening the page is using iOS6 or not. var startIndex = navigator.userAgent.search(/OS/i) + 2; var endIndex = navigator.userAgent.search(/like/i); var iOSVersion = parseInt(navigator.userAgent.substr(startIndex,endIndex - startIndex).trim()); this.iOSVersion = true; if(!isNaN(iOSVersion)){ this.iOSVersion = iOSVersion; } else if(Ext.is.Desktop){ this.iOSVersion = true; } The above code works well for all the versions of browsers. But incase of using it in iOS6, it shows as iOS5. Searched for the same thing, but I didn't find a solution. May be I am still not done with searching for this, doing side by side search and hoping if some one has faced this issue before. Any suggestions or updations?

    Read the article

  • Thread testing for time

    - by DanielFH
    Hi there :) I'm making a thread for my application that's going to do an exit operation at a given time (only hours and minutes, day/month doesn't matter). Is this the right way to do it, and also the right way to test for time? I'm testing for a 24 hour clock by the way, not AM / PM. I'm then in another class going to call this something like new Thread(new ExitThread()).start(); public class ExitThread implements Runnable { @Override public void run() { Date date = new Date(System.currentTimeMillis()); String time = new SimpleDateFormat("HHmmss").format(date); int currentTime = Integer.parseInt(time); int exitTime = 233000; while(true) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } if(currentTime >= exitTime ) { // do exit operation here } } } Thanks. //D

    Read the article

  • Why do I get a nullpointerexception at line ds.getPort in class L1?

    - by Fred
    import java.awt.; import java.awt.event.; import javax.swing.; import java.io.; import java.net.; import java.util.; public class Draw extends JFrame { /* * Socket stuff */ static String host; static int port; static int localport; DatagramSocket ds; Socket socket; Draw d; Paper p = new Paper(ds); public Draw(int localport, String host, int port) { d = this; this.localport = localport; this.host = host; this.port = port; try { ds = new DatagramSocket(localport); InetAddress ia = InetAddress.getByName(host); System.out.println("Attempting to connect DatagramSocket. Local port " + localport + " , foreign host " + host + ", foreign port " + port + "..."); ds.connect(ia, port); System.out.println("Success, ds.localport: " + ds.getLocalPort() + ", ds.port: " + ds.getPort() + ", address: " + ds.getInetAddress()); Reciever r = new Reciever(ds); r.start(); } catch (Exception e) { e.printStackTrace(); } setDefaultCloseOperation(EXIT_ON_CLOSE); getContentPane().add(p, BorderLayout.CENTER); setSize(640, 480); setVisible(true); } public static void main(String[] args) { int x = 0; for (String s : args){ if (x==0){ localport = Integer.parseInt(s); x++; } else if (x==1){ host = s; x++; } else if (x==2){ port = Integer.parseInt(s); } } Draw d = new Draw(localport, host, port); } } class Paper extends JPanel { DatagramSocket ds; private HashSet hs = new HashSet(); public Paper(DatagramSocket ds) { this.ds=ds; setBackground(Color.white); addMouseListener(new L1(ds)); addMouseMotionListener(new L2()); } public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.black); Iterator i = hs.iterator(); while(i.hasNext()) { Point p = (Point)i.next(); g.fillOval(p.x, p.y, 2, 2); } } private void addPoint(Point p) { hs.add(p); repaint(); } class L1 extends MouseAdapter { DatagramSocket ds; public L1(DatagramSocket ds){ this.ds=ds; } public void mousePressed(MouseEvent me) { addPoint(me.getPoint()); Point p = me.getPoint(); String message = Integer.toString(p.x) + " " + Integer.toString(p.y); System.out.println(message); try{ byte[] data = message.getBytes("UTF-8"); //InetAddress ia = InetAddress.getByName(ds.host); String convertedMessage = new String(data, "UTF-8"); System.out.println("The converted string is " + convertedMessage); DatagramPacket dp = new DatagramPacket(data, data.length); System.out.println(ds.getPort()); //System.out.println(message); //System.out.println(ds.toString()); //ds.send(dp); /*System.out.println("2Sending a packet containing data: " +data +" to " + ia + ":" + d.port + "...");*/ } catch (Exception e){ e.printStackTrace(); } } } class L2 extends MouseMotionAdapter { public void mouseDragged(MouseEvent me) { addPoint(me.getPoint()); Point p = me.getPoint(); String message = Integer.toString(p.x) + " " + Integer.toString(p.y); //System.out.println(message); } } } class Reciever extends Thread{ DatagramSocket ds; byte[] buffer; Reciever(DatagramSocket ds){ this.ds = ds; buffer = new byte[65507]; } public void run(){ try { DatagramPacket packet = new DatagramPacket(buffer, buffer.length); while(true){ try { ds.receive(packet); String s = new String(packet.getData()); System.out.println(s); } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } }

    Read the article

  • jQuery timer, ajax, and "nice time"

    - by Mil
    So for this is what I've got: $(document).ready(function () { $("#div p").load("/update/temp.php"); function addOne() { var number = parseInt($("#div p").html()); return number + 1; } setInterval(function () { $("#div p").text(addOne()); }, 1000); setInterval(function () { $("#geupdate p").load("/update/temp.php");} ,10000); }); So this grabs a a UNIX timestamp from temp.php and puts into into #div p, and then adds 1 to it every second, and then every 10 seconds it will check the original file to keep it up to speed. My problem is that I need to format this UNIX timestamp into a format such as "1 day 3 hours 56 minutes and 3 seconds ago", while also doing all the incrementation and ajax calls. I'm not very experienced with jquery/javascript, so I might be missing something basic.

    Read the article

  • why is internet explorer displaying my javascript pagination backwards?

    - by user278457
    Here's a version of the code I'm using, stripped down to just the parts that aren't working. This is all written to generate some basic pagination with jQuery. In Chrome/Safari/Moz, I generate see spans, 1,2,3,4,...,etc When I look in IE7/8, I see etc,...,4,3,2,1 The string seems to be concatenating backwards!! This seems very strange to me, because there's not a whole lot going on in the code here, I can't figure out which bit could be causing problems. Obviously, the 1,2,3,4,...,etc is what I'm aiming for here, so as well as an explanation of why this is an issue, I'd love it if someone could offer a quick fix. myVar = { arr:$.makeArray($('.my_li')) }; var str; str=''; for (s in myVar.arr){ r=parseInt(s,10)+1; str+='<span class="my_class">'+r+'</span>'; } $('#my_other_div').html(str);

    Read the article

  • Better way to write this Java code?

    - by Macha
    public void handleParsedCommand(String[] commandArr) { if(commandArr[0].equalsIgnoreCase("message")) { int target = Integer.parseInt(commandArr[1]); String message = commandArr[2]; MachatServer.sendMessage(target, this.conId, message); } else if(commandArr[0].equalsIgnoreCase("quit")) { // Tell the server to disconnect us. MachatServer.disconnect(conId); } else if(commandArr[0].equalsIgnoreCase("confirmconnect")) { // Blah blah and so on for another 10 types of command } else { try { out.write("Unknown: " + commandArr[0] + "\n"); } catch (IOException e) { System.out.println("Failed output warning of unknown command."); } } } I have this part of my server code for handling the types of messages. Each message contains the type in commandArr[0] and the parameters in the rest of commandArr[]. However, this current code, while working seems very unelegant. Is there a better way to handle it? (To the best of my knowledge, String values can't be used in switch statements, and even then, a switch statement would only be a small improvement.

    Read the article

  • Php variable in several files including jquery

    - by vipinsahu
    i created two variable and these two variable are using everywhere . i don't want to store these variable in to database e.g ( $username ,$password and there are 3 files using these variable load.php,index.php and add.php , i am also using jquery to load the add.php as in ajax (to add the user in JSON) $.ajax({ type: "POST", url: "add.php", data: "twitter="+encodeURIComponent(twitter), /* Sending the filled in twitter name */ success: function(msg){ /* PHP returns 1 on success, and 0 on error */ var status = parseInt(msg); if(status) { $('#response').html('Thank you '); $('#twitterName').val(''); } else $('#response').html('<span style="color:red">There is no user.</span>'); } }); how can i use these two variable in a single file to perform the whole operation Thanks

    Read the article

  • javascript switch using internals

    - by Fernando SBS
    Can I use intervals in a switch statement? Like switch (parseInt(troops[i])) { case <10: editbox.style.fontSize = "13px"; break; case <100: editbox.style.fontSize = "12px"; break; case <1000: editbox.style.fontSize = "8px"; editbox.size = 3; //editbox.style.width = "18px"; break; default: editbox.style.fontSize = "10px"; } ???

    Read the article

  • jQuery : how to manipulate indexes?

    - by Gabriel Theron
    Should not be such a hard question... I'm just having a hard time figuring out how to make operations on some jquery elements, particularly their indexes. Teh codez: $( "#docSlider" ).css("background-image", "url(../../bundles/mypath/images/maquette/img" + $( "#selectable li" ).index( this ) + (".jpg)")); I want to make the name of the picture I load depend on the index of a jQuery selectable. So I grab the index and try to add 1... but it can't work because "+" is also a concatenator. I've tried to parseInt as well, but it was always worth 0. How do I simply transform the index to an integer and then concatenate it with the rest of the string? Thank you in advance! Edit : I'm using a function that already exists, so I can hardly change the parameters (well, I guess I can't...)

    Read the article

  • jQuery Custom Lightbox issue

    - by Neurofluxation
    I have been writing my own Lightbox script (to learn more about jQuery). My code for the captions are as follows (the problem is that the captions are the same on every image): close.click(function(c) { c.preventDefault(); if (hideScrollbars == "1") { $('body').css({'overflow' : 'auto'}); } overlay.add(container).fadeOut('normal'); $('#caption').animate({ opacity: 0.0 }, "5000", function() { $('div').remove('#caption'); }); }); $(prev.add(next)).click(function(c) { c.preventDefault(); $('div').remove('#caption') areThereAlts = ""; var current = parseInt(links.filter('.selected').attr('lb-position'),10); var to = $(this).is('.prev') ? links.eq(current - 1) : links.eq(current + 1); if(!to.size()) { to = $(this).is('.prev') ? links.eq(links.size() - 1) : links.eq(0); } if(to.size()) { to.click(); } });

    Read the article

  • PHP validating integers

    - by Mikk
    Hi, I was wondering, what would be the best way to validate an integer. I'd like this to work with strings as well, so I could to something like (string)+00003 - (int)3 (valid) (string)-027 - (int)-27 (valid) (int)33 - (int)33 (valid) (string)'33a' - (FALSE) (invalid) That is what i've go so far: function parseInt($int){ //If $int already is integer, return it if(is_int($int)){return $int;} //If not, convert it to string $int=(string)$int; //If we have '+' or '-' at the beginning of the string, remove them $validate = ($int[0] === '-' || $int[0] === '+')?substr($int, 1):$int; //If $validate matches pattern 0-9 convert $int to integer and return it //otherwise return false return preg_match('/^[0-9]+$/', $validate)?(int)$int:FALSE; } As far as I tested, this function works, but it looks like a clumsy workaround. Is there any better way to write this kind of function. I've also tried filter_var($foo, FILTER_VALIDATE_INT); but it won't accept values like '0003', '-0' etc.

    Read the article

  • redirect inputStream to JTextField

    - by gt_ebuddy
    I want to redirect the Standard System input to JTextField, So that a user must type his/her input in JTextField (instead of console.) I found System.setIn(InputStream istream) for redirecting System.in. Here is my scratch code where i confused on reading from JTextField - inputJTextField. System.setIn(new InputStream() { @Override public int read() throws IOException { //how to read content? return Integer.parseInt(inputJTextField.getText()); } }); My Question is how to read content from GUI Component ( like JTextField and Cast it to String and other types after redirecting the input stream?

    Read the article

  • javascript switch using intervals

    - by Fernando SBS
    Can I use intervals in a switch statement? Like switch (parseInt(troops[i])) { case <10: editbox.style.fontSize = "13px"; break; case <100: editbox.style.fontSize = "12px"; break; case <1000: editbox.style.fontSize = "8px"; editbox.size = 3; //editbox.style.width = "18px"; break; default: editbox.style.fontSize = "10px"; } ???

    Read the article

  • how can i acess a variable outside of an if statement in java

    - by themanepalli
    i have defined a variable inside an if statement and I am trying to access it outside of that if statement now. now the error is saying that it cannot find the symbol which is because its being defined as an intance variable, is there a way i can change it so i can access it outside the variable? heres the code if((e.getSource()==userOrder2)&& (orderType==1)) { String buyO= userOrder2.getText(); int buyOrder= Integer.parseInt(buyO); //variable im trying to access } // trying to use buyOrder in a different if statement if(orderType==1 && (stockPrice <= buyOrder)) { orderResult.setText("The Stock" + (stockName2.getText()) + "was bought at" + stockPrice); }

    Read the article

  • How do I output JSON columns in jQuery

    - by Mel
    I'm using the qTip jQuery plugin to create dynamic tool tips. The tooltip sends an id to a cfc which runs a query and returns data in JSON format. At the moment, the tooltip loads with the following: {"COLUMNS:" ["BOOKNAME","BOOKDESCRIPTION"["MYBOOK","MYDESC"]]} Here's the jQuery $('#catalog a[href]').each(function() { var gi = parseInt($(this).attr("href").split("=")[1]) $(this).qtip( { content: { url: 'cfcs/viewbooks.cfc?method=bookDetails', data: { bookID: gi }, method: 'get', title: { text: $(this).text(), button: 'Close' } }, api :{ onContentLoad : function(){ } }, }); }); As I mentioned, the data is returned successfully, but I am unsure how to output it and format it with HTML. I tried adding content: '<p>' + data.BOOKNAME + '' to api :{ onContentLoad : function(){ ..... to see if I could get it to output something, but I get a 'data is undefined error' What is the correct way to try and output this data with html formatting? Many thanks!

    Read the article

  • Strange result of highchart

    - by user1612334
    I use http://highcharts.com and there is really strange result. So, my data looks like: Value | Date 1507 2013-02-03 734 2013-02-02 0 2013-02-01 225 2013-01-31 *Graphic miss* 672 2013-01-30 *Graphic miss* 692 2013-01-29 *Graphic miss* <--- This value gone to 1 february 910 2013-01-28 314 2013-01-27 I miss three days (29 January, 30, 31). When i get data from database, i convert it so: var lines = []; try { jQuery.each(data, function(i, line) { var dateArr = line.date.split('-'); lines.push([ Date.UTC(dateArr[0],dateArr[1],dateArr[2]), parseInt(line.num_chips) ]); }); } catch(e) { } Why could it be so? =\

    Read the article

  • Attaching a function to the parent window from an iframe and getting proper scope

    - by Ronald
    I working on adding file uploading to my web application. I'm using an iframe to post my upload. When my php script processes the upload it writes some JavaScript to the iframe. This JavaScript is attempting to attach a function to the parent, this works, but when this function actually gets called it doesn't have the correct scope. Here is the code I'm attaching to the parent window: parent.window.showPreview = function(coords) { if (parseInt(coords.w) > 0) { var rx = 200 / coords.w; var ry = 250 / coords.h; $('#preview').css({ width: Math.round(rx * 400) + 'px', height: Math.round(ry * 533) + 'px', marginLeft: '-' + Math.round(rx * coords.x) + 'px', marginTop: '-' + Math.round(ry * coords.y) + 'px' }); } } When this function gets executed I get an error that says $ is not defined. I've tried adding changing the JQuery call to parent.$('#preview').css..., but then it says that parent is undefined. Any ideas?

    Read the article

  • Scanner's Read Line returning NoSuchElementException

    - by Brian
    This is my first time using StackOverflow. I am trying to read a text file which consists of a single number one the first line. try { Scanner s = new Scanner(new File("HighScores.txt")); int temp =Integer.parseInt(s.nextLine()); s.close(); return temp; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } However, I get an error: java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at GameStart.getHighScore(GameStart.java:334) at GameStart.init(GameStart.java:82) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) I know that HighScores.txt is not empty, so why is this problem occuring? I tried using BufferedReader, and BufferReader.readLine() return null.

    Read the article

  • How to get jQuery animateNumber to pull value dynamically?

    - by mcography
    I am trying to implement jQuery animateNumber, and I have it working like the demo just fine. However, I want to modify it so that it pulls the number from the HTML, rather than setting it in the script. I tried the following, but it just shows "NAN." What am I doing wrong? <div class="stat-title animate-number">$16,309</div> <script> $('.animate-number').each(function(){ var value = new Number; // Grab contents of element and turn it into a number value = $(this).text(); value = parseInt(value); // Set the starting text to 0 $(this).text('0'); $(this).animateNumber( { number: value, }, 1000 ) }); </script>

    Read the article

  • How to copy a subset from an array of strings to an array of ints using Groovy?

    - by Cuga
    I have a String array in a Groovy class (args to a main method): String[] args I'd like to convert the 3rd to the last element into a new array of ints. Is there an easier way to do this in Groovy other than: final int numInts = args.length - 2 final int [] intArray = new int[numInts] for (int i = 2; i < args.length; i++) { intArray[i-2]=Integer.parseInt(args[i]) } I wanted to do: final int numInts = args.length - 2 final int [] intArray = new int[numInts] System.arraycopy(args, 2, intArray, 0, numInts) But it throws a class cast exception. Thanks!

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >