1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JavaScript sorter problem.

Discussion in 'JavaScript' started by sweetboy1, Jun 25, 2014.

  1. #1
    pleas help me ,this "Nr and Words Sorter Script" wrkg good but the problem is it dosent sort word vertically,only horizontaly what i have to change in the script ? thnks for helping

    example if we paste in textarea word-nr list vertical
    
      benito
      albano
      zalo
      xxx
      321
      1
      23
    
    Code (markup):
    the script dosent sort , if we paste horizontaly txt :
    benito albano zalo xxx 321 1 23
    Code (markup):
    etc its work ,the question is what to change to make script wrk in both ways , thnks

    
    
      <script type="text/javascript">
       
      function sortit(a,b){
      return(a-b)
      }
       
      function sortvalues(param){
      var inputvalues=document.sorter.sorter2.value.split(" ")
      if (param==0) //if sort alphabetically
      inputvalues.sort()
      else //else if sort numerically
      inputvalues.sort(sortit)
      document.sorter.sorter2.value=''
      for (i=0;i<inputvalues.length-1;i++)
      document.sorter.sorter2.value=document.sorter.sorter2.value+inputvalues[i]+" "
      document.sorter.sorter2.value+=inputvalues[inputvalues.length-1]
      }
      </script>
       
      <form name="sorter">
      <p>
      <textarea rows="10" name="sorter2" cols="50" wrap="virtual"></textarea><br>
      <input type="button" value="Sort alphabetically" onClick="sortvalues(0)">
      <input type="button" value="Sort numerically" onClick="sortvalues(1)">
      <input type="reset" value="Reset">
      </form> 
    Code (markup):
     
    Solved! View solution.
    sweetboy1, Jun 25, 2014 IP
  2. #2
    Hello sweetboy1.
    Try use javascript Regular Expression for line #10, like the following:
    var inputvalues=document.sorter.sorter2.value.split(/[\n ]/);
     
    hdewantara, Jun 25, 2014 IP
  3. sweetboy1

    sweetboy1 Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    thank you so much my friend its work thank you soo much
     
    sweetboy1, Jun 25, 2014 IP
  4. sweetboy1

    sweetboy1 Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    i really apreciate yout help thank you so much
     
    sweetboy1, Jun 25, 2014 IP
  5. sweetboy1

    sweetboy1 Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #5
    Helllo,

    the script work good but i have 1 more question what i have to modify in this same script ,to replace or remove "@" if text contains "@" soo in results "@" to be remove or replaced with something else..
    i try with
    var inputvalues=document.sorter.sorter2.value.split(/[\n ]/).split("@").join("");
    Code (markup):
    but dosent work.
    thank you
     
    sweetboy1, Jul 2, 2014 IP