Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

i have attached the screenshot of my output. Now its an array format, i want to split those array values from javascript.

View File:

<form name="sortdata" method="POST" action="<?php echo base_url;?>home/sortby">
<select id="sortMyData" name="sortMyData" class="sortMydata">
    <option value="lowhigh">Low to high price</option>
    <option value="highlow">High to low price</option>
</select>
<input type="hidden" id="baseurl" name="baseurl" value="<?php echo base_url;?>">
</form>

<div id="sortbyprice" class="span6">


</div>

<script type="text/javascript">
$(document).ready(function()
{
    $(".sortMydata").change(function()
{
var baseurl=$("#baseurl").val();
var sortMyData=$("#sortMyData").val();
//alert(baseurl);
alert(sortMyData);
$.ajax
({
type:"GET",
url:baseurl + 'product/sortbydetails/' + sortMyData,
//data:this.value,
cache: false,
success:function(html)
    { 
        var length=html.length;
        alert(html);
        alert(html[0]); 

    }
});
});
});
</script>

Controller:

public function sortbydetails()
    {
        $lowhigh=$this->uri->segment(3);
        if($lowhigh=="lowhigh")
        {
            $lowtohighprice=$this->product_model->getlowtohighprice();  
            $count=count($lowtohighprice);
            //echo $count;

            for ($i=0; $i < $count ; $i++) 
                { 

                    foreach ($lowtohighprice as $key => $value) {
                    $sortby[] = array_values($value);

                }
                    print_r($sortby);
            }
            //print_r($lowtohighprice);
        }
        else
        {
            $hightolowprice=$this->product_model->gethightolowprice();
            //print_r($hightolowprice);
        }

    }

I am trying to split the array values from javascript. I wrote an jquery ajax code and display the output in a div. Now am getting the output as an array values, i want to split that array values. I spend a whole day to achieve this task, but i couldnt able to resolve.

share|improve this question
    
we use split function to make an array from a string which has repetition of a character.what you exactly asking for? –  ABorty Sep 14 '13 at 14:28
    
You should use console.log() rather than alert(). It's much easier to work with, and the output will arrive in the JavaScript console you already have showing up on your screen. –  doppelgreener Sep 16 '13 at 4:35

1 Answer 1

up vote 1 down vote accepted

I could not get what you want exactly. You can use any loop to get all values from array.

var myarray = [1,2,3,4];
for(var i= 0; i< myarray.length; i++)
{
alert(myarray[i]);
}

EDIT:

For 2 dimensional arrays

var myarray = [[1,2,3,4], [5,6,7,8]];
for(var i= 0; i< myarray.length; i++)
  for(var j=0; j < myarray[i].length; j++)
     {
      alert(myarray[i][j]);
     }
share|improve this answer
    
i have attached the screenshot of my output. Now its an array format, i want to split those array values from javascript. –  Naveen Sep 16 '13 at 4:33
    
I have update my answer for 2 dimensional array. –  sudhAnsu63 Sep 16 '13 at 7:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.