Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1033321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:12:52+00:00 2026-05-16T14:12:52+00:00

I have a problem with the split() function. I get the error undefined but

  • 0

I have a problem with the split() function.
I get the error undefined but it dont know why :/

It is easier to explain with a working example: http://www.jsfiddle.net/V9Euk/415/

$(function start()
{
    css('#div { font-color:#ff0000; border:1px solid #00ff00; }', '#div_2 { font-color:#ff0000; }', '#line2 { font-color:#00ffff; }');
});


function css(c0,c1,c2)
{
    if(c0 != 'undefined')
    {
        c0_selector = c0.match(/^.*{/);
        c0 = c0.replace(/^.*{/,'');
        c0 = c0.replace(/}/,'');
        c0_arr = c0.split(';');        
        values = new Array();
        values[0] = new Array();
        values[0][0] = c0_selector;  
        for (i = 1; i < c0_arr.length; i++)
        {
            values[0][i]= c0_arr[i].split(':');
        }
    }

    if(c1 != 'undefined')
    {
        c1_selector = c1.match(/^.*{/);
        c1 = c1.replace(/^.*{/,'');
        c1 = c1.replace(/}/,'');
        c1_arr = c1.split(';');  
        values[1] = new Array();        
        values[1][0] = c1_selector;
        for (i = 1; i < c1_arr.length; i++)
        {
            values[1][i]= c1_arr[i].split(':');
        }
    }

    $('#log').append(''+values[0][0]+'<br />');  
    $('#log').append(''+values[0][1][0]+'<br />');          
    $('#log').append(''+values[0][1][1]+'<br />');   
    $('#log').append('<hr />');  
    $('#log').append(''+values[1][0]+'<br />');      
    $('#log').append(''+values[1][1][0]+'<br />');          
    $('#log').append(''+values[1][1][1]+'<br />');       

    $.ajax({
            url: 'test.php',
            type: 'POST',
            dataType: 'json',
            data: $.toJSON(values),
            contentType: 'application/json; charset=utf-8',
            success: function() {
                alert('success');
            }
    });

}

Thanks in advance!
Peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:12:53+00:00Added an answer on May 16, 2026 at 2:12 pm

    Your for loops are wrong.

    c0_arr = c0.split(';');
    

    You get indexes 0 and 1 containing stuff after that.

    And then you loop like this:

    for (i = 1; i < c0_arr.length; i++)
    {
       values[0][i]= c0_arr[i].split(':');
    }
    

    Starting at index 1.
    You should start at index 0, and fill your values array like this:

    for (i = 0; i < c0_arr.length; i++)
    {
       values[0][i+1]= c0_arr[i].split(':');
    }
    

    Then you will get all your values where they belong.

    Previous answer explains clearly why you get the undefined error BTW.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem where I need to split an input string into possible
I have a table that is split into 3. My problem is I have
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem SIMILAR to preventing form data reposting, but not quite the same
I have problem developing with live555. I already build the lib-files and example projects
So, I'm using JQuery AjaxQueue to do stuff, but the problem I have is
I have below probably a bunch of problems but let's simplify them with easier
I have a problem with string.split using.NET 3.5: String to split is: dim source
i have a problem to build following regex: [1,2,3,4] i found a work-around, but
i have a problem with this jquery, in the success function call, its mean

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.