1. No Profile Picture
    Devshed Newbie (0 - 499 posts)
    Hi all,

    Can anybody tell me how to read the first 6 characters of Text-box?
    I think I have to use indexOf but don't know how it works


    Henk Emmelot
  2. #2
  3. No Profile Picture
    Ulf Wendel
    Devshed Newbie (0 - 499 posts)
    Moin Henk,

    indexOf() is not the function that matches your question. The question for indexOf() is "does the string contain this substring".

    Your question is "give me the first n characters". This is a job for substr().

    (pseudo code!)

    n = 5;
    sub = "";

    value = document.forms.elements[..].value;

    if (""!=value && value.length>=n) {
    sub = value.substr(0,n);


Similar Threads

  1. Get number of lines
    By gurrutello in forum ASP Programming
    Replies: 11
    Last Post: October 14th, 2003, 12:01 PM
  2. Single and double quotes in form text input box?
    By CraigSmith in forum PHP Development
    Replies: 10
    Last Post: August 19th, 2003, 07:02 PM
  3. non-editable text box
    By Joruus in forum HTML Programming
    Replies: 4
    Last Post: January 7th, 2002, 02:31 PM
  4. Passing desc from select box into text box
    By acetone_lin in forum HTML Programming
    Replies: 2
    Last Post: August 31st, 2001, 06:16 PM
  5. Limitation on characters in a text box
    By jaxie in forum HTML Programming
    Replies: 1
    Last Post: November 8th, 2000, 10:34 AM

IMN logo majestic logo threadwatch logo seochat tools logo