Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

"Number Expected" Error in IE 11 with .toISOString()

Posted on 2016-08-11
3
Medium Priority
?
381 Views
Last Modified: 2016-08-17
I'm getting the error "Number expected" at the line:

new Date($('#itemOpenDate').val()).toISOString()

Open in new window



where $('#itemOpenDate').val() is a string representing a date, e.g. "8/11/2016"

No problems in the latest version of Chrome, Firefox, and Safari. Should be supported in IE11 per the documentation. Am I missing something?
0
Comment
Question by:Michael Vasilevsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 41756131
go over, don't fight with IE, use this :
var arr = $('#itemOpenDate').val().split("/");
new Date(arr[2], arr[0]*1-1, arr[1]).toISOString();

Open in new window

0
 
LVL 10

Author Comment

by:Michael Vasilevsky
ID: 41757359
That should work, but IE 11 gives me NaN for arr[0] * 1 - 1. Other browsers return the expected...

I've narrowed it down to how I'm populating the form field. See the below code. For line 43, the following works in IE11:

$('#itemOpenDate').val(new Date("8/2/2016").toDateString());

Open in new window


but I want the locale string format "8/2/2016", and the following breaks (in IE11 only):

$('#itemOpenDate').val(new Date("8/2/2016").toLocaleString());

Open in new window


Any ideas?

<!doctype html>
<html>
<head>
    <title></title>
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" >

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>

</head>
<body>

    <div class="container" role="main">
        <form class="center-block form-horizontal">
            <div class="form-group">
                <label for="itemOpenDate" class="control-label">Open Date:</label>
                <input type="text" class="form-control input-lg" id="itemOpenDate">
            </div>
            
            <div class="form-group">
                <button id="updateItemButton"  title="Update Item" type="button" class="btn btn-primary btn-lg btn-block">Update</button>
            </div>

        </form>

    </div>

<script type="text/javascript">

$(document).ready(function () {

    $("#itemOpenDate").datepicker();

    getPunchlistItem();

    $("#updateItemButton").click(function () {
        updatePunchlistItem();
    });
});
    
function getPunchlistItem(myPLItemID) {
    $('#itemOpenDate').val(new Date("8/2/2016").toLocaleString());
}

function updatePunchlistItem() {

    var myOpenDate = new Date($('#itemOpenDate').val()).toISOString();
    console.log(myOpenDate);

}


</script>

</body>

</html>

Open in new window

0
 
LVL 10

Author Comment

by:Michael Vasilevsky
ID: 41759018
I got it to work by using momentjs in line 43, instead of
toLocaleString()

Open in new window

:

$('#itemOpenDate').val(moment("8/2/2016").format("L"));

Open in new window

0

Featured Post

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question