Web Analytics Made Easy -
StatCounter Croping a VAR - CodingForum

Announcement

Collapse
No announcement yet.

Croping a VAR

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Croping a VAR

    Hi,

    I have programmed a var (contains postcode information) ,however I wish to crop it down so that I only get returned the value's before a " " has been entered e.g.

    If a value of "SO22 6NT" is entered I only want the SO22 in the var,

    I can do this in Basic using Instr but dont know how to do this in Javascript, can anyone point me in the correct direction,

    Thanks

    Nick Gibbons

  • #2
    this will do it

    var str = "SO22 6NT"
    str = str.substring(0, str.indexOf(" "));

    Comment


    • #3
      That worked a treat thanks!

      Comment

      Working...
      X