I am using below script for showing slide show on page. I am concatenating images at codebehind from database and storing in hiddenfield and accessing it on clientside. This hiddenfield return string like this
I have to pass it as array and thats creating a problem. I need to remove double quotes ( " ) from starting and ending position of the string to showing slide show on page. Is there any way to do this.
$(document).ready(function () {
imgs = $("#MainContent_HiddenField1").val();
var mygallery = new simpleGallery({
wrapperid: "simplegallery1",
dimensions: [250, 180],
imagearray: imgs,
autoplay: [false, 2500, 2],
persist: false,
fadeduration: 500,
oninit: function () {
},
onslide: function (curslide, i) {
I want string like this [["images/p1.jpg"," ","this is image"," "],["images/p2.jpg"," ",""," "],["images/p1.jpg"," ",""," "],["images/p2.jpg"," ",""," "]]
var imgs = $("#MainContent_HiddenField1").val();
var imgArr = JSON.parse(imgs);
// or
//var imgArr = eval($("#MainContent_HiddenField1").val());
//and then use imgArr
imagearray: imgArr
smartymca
Member
78 Points
188 Posts
Need to remove double quotes from string in javascript
Jan 05, 2013 03:21 PM|LINK
I am using below script for showing slide show on page. I am concatenating images at codebehind from database and storing in hiddenfield and accessing it on clientside. This hiddenfield return string like this
"[["images/p1.jpg"," ","this is image"," "],["images/p2.jpg"," ",""," "],["images/p1.jpg"," ",""," "],["images/p2.jpg"," ",""," "]]"
I have to pass it as array and thats creating a problem. I need to remove double quotes ( " ) from starting and ending position of the string to showing slide show on page. Is there any way to do this.
$(document).ready(function () {
imgs = $("#MainContent_HiddenField1").val();
var mygallery = new simpleGallery({
wrapperid: "simplegallery1",
dimensions: [250, 180],
imagearray: imgs,
autoplay: [false, 2500, 2],
persist: false,
fadeduration: 500,
oninit: function () {
},
onslide: function (curslide, i) {
}
})
});
Pune,India
roopeshreddy
All-Star
20135 Points
3323 Posts
Re: Need to remove double quotes from string in javascript
Jan 06, 2013 05:24 AM|LINK
Hi,
Check this logic -
var mystring = new String("\"MyData\""); mystring = mystring.substring(1, mystring.length - 1); alert(mystring);Hope it helps u...
Roopesh Reddy C
Roopesh's Space
smartymca
Member
78 Points
188 Posts
Re: Need to remove double quotes from string in javascript
Jan 06, 2013 06:20 AM|LINK
I want string like this [["images/p1.jpg"," ","this is image"," "],["images/p2.jpg"," ",""," "],["images/p1.jpg"," ",""," "],["images/p2.jpg"," ",""," "]]
Pune,India
roopeshreddy
All-Star
20135 Points
3323 Posts
Re: Need to remove double quotes from string in javascript
Jan 06, 2013 06:48 AM|LINK
Hi,
Yeah! The above logic works!
Suppoose you have that string in a variable, say myData!
So the code will be -
<script type="text/javascript"> myData= myData.substring(1, myData.length - 1); alert(myData); </script>Hope it helps u...
Roopesh Reddy C
Roopesh's Space
raju dasa
Star
14330 Points
2440 Posts
Re: Need to remove double quotes from string in javascript
Jan 07, 2013 05:03 AM|LINK
Hi,
Either u can use JSON.parse() or eval()
check this:
var imgs = $("#MainContent_HiddenField1").val(); var imgArr = JSON.parse(imgs); // or //var imgArr = eval($("#MainContent_HiddenField1").val()); //and then use imgArr imagearray: imgArror check this site:
http://www.json.org/js.html
rajudasa.blogspot.com || blog@opera