0

Below Code giving an error called

"expected identifier in function getdetails"

$( document ).ready(function() { 

    qString = getdetails();
});


function getdetails( {
 var result = window.location.href.split("?ID=")[1];
 return result;
});

Can you please assist me to resolve it?

Asad Refai
  • 5,971
  • 8
  • 34
  • 57
user52650
  • 61
  • 1
  • 1
  • 9

4 Answers4

2

Your code fails because the Function declaration is wrong:

You do:

function getdetails( {dosomething} )

But the correct way of declaring a function is:

function getdetails() {dosomething}

BUT, More potential errors:

Your code tries to extract the ID value when it is the first QueryString parameter in the URL

So it fails:

  • When ID is not immediatly after the ? QueryString identifier

  • When there is no ID in the QueryString

SharePoint provides you at least 4 ways of getting a QueryString value:

What does this code getQueryStringParameter do?

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
1

var result; $( document ).ready(function() { getdetails(); var qString = result; });

function getdetails() { result = window.location.href.split("?ID=")[1]; return result; }

Ram
  • 2,444
  • 2
  • 19
  • 38
0

Please try below mentioned code.

var result;
$( document ).ready(function() { 
     getdetails();
     var qString = result;
});

function getdetails() 
{
   result = window.location.href.split("?ID=")[1];
}
Hardik
  • 7,733
  • 2
  • 18
  • 37
0

Please check the getdetails function.Code is inside ()

 function getdetails(){ var result = window.location.href.split("?ID=")[1]; return result;};
Sharanya
  • 650
  • 9
  • 21