www.webdeveloper.com
Results 1 to 4 of 4

Thread: var to string or integer

  1. #1
    Join Date
    Apr 2010
    Posts
    52

    var to string or integer

    How can i convert variable to string or integer in javascript???

    the for loop in the else portion is not getting executed as it is taking it as a variable and concatenating the string for var i=numOpts+1;
    code


    function addOptions(numOpts)

    {

    var selO = document.getElementById("mySelect");

    if (numOpts != selO.options.length)
    {
    if(numOpts > selO.options.length)
    {
    var a;
    a = (numOpts - selO.options.length);
    for (var i=selO.options.length+1 ;i<=numOpts;i++)
    {
    alert("page " + i + " will be dded" );
    }
    //alert (+a);
    }

    else
    {



    var b;
    b = (selO.options.length - numOpts);
    for (var i=numOpts+1; i<=selO.options.length;i++)
    {
    alert("Page " + i + " will be Deleted" );
    }
    }

    }

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    what are the actual values of numOpts and selO.options.length immediately after this line?
    Code:
     
     
    var selO = document.getElementById("mySelect");

  3. #3
    Join Date
    Jul 2005
    Location
    USA
    Posts
    909
    parseInt(value)

    returns an integer
    Bitter web veteran

  4. #4
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by Webnerd View Post
    parseInt(value)

    returns an integer
    in fact the method is

    parseInt(value,base)

    Despite the general belief, the default base is not 10 all the time...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles