Click here to Skip to main content
15,791,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a form which contains textboxes,"search" button.when user enter the values and click on the button I have to display the search details. and I have to display no.of searchresults: no.of search results i have obtained by using array.length; I want to use this value in another view I put this value in the sessionStorage.setItem("getCount",len); I am concatinating this value in the other view page like:

Search Results:" + sessionStorage.getItem('getCount') + "

I am getting the number of search results when user enters the value in the form. but when user enter no values in the form then at the searchresults: it is displaying "null".but i want to display "0" insted of null. how can i do this.
Updated 13-Aug-12 2:36am
Santhosh Kumar Jayaraman 13-Aug-12 6:50am    
which language you are using?
charan1431 13-Aug-12 6:51am,mvc3 and html5
Kenneth Haugland 13-Aug-12 6:51am    
Think you need to hardcode it :)

If you're using C# then a simple if-else statement should work. Something like:
..."Search Results:" + sessionStorage.getItem('getCount') == null ? 0 : (int)sessionStorage.getItem('getCount')
Share this answer
charan1431 13-Aug-12 7:14am    
I gave like this
Search Results:" + sessionStorage.getItem('getCount') == null ? 0 :sessionStorage.getItem('getCount') + "
It is displaying only "null",not even displaying SearchResults: also
Though you not mentioned here what language you used for coding but it may be something like that...
if(sessionStorage.getItem('getCount').toString() == '0')
  then print 0;  //or your preferred message
  Search Results:" + sessionStorage.getItem('getCount') + "  //your preferred work
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900