Results 1 to 2 of 2

Thread: how to split a variable on javascript?

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question how to split a variable on javascript?

    please look at this

    on php code, i can slipt a valiable and print it:


    <?php
    $text="john = 34";
    list($name,$age) = split("=",$text);
    echo $name."'s age is ".$age;
    ?>


    can anyone help me to split same variable on javascript?

    <script type="text/javascript">
    var text = "john = 34";
    //--- what should i write here?--//
    //--- what should i write here?--//
    //--- what should i write here?--//
    </script>

    thanks so much
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    hi, i have gotten the answer

    <script type="text/javascript">
    var text = "john = 34";
    document.write(text.split("=")[0]); // this will print "john"
    </script>

    thaks
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •