SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: startsWith()

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    startsWith()

    I'm trying to check a element in a form's name and see if it starts with a certain thing, and I'm using .startsWith(), but it's giving me an error.

    Anyone know what's wrong, or know another function?

    Here's what I have:

    Code:
    	this.msgselected = false;
    	this.msgarray = new Array();
    	this.msgnum = 0;
    	for (var i = 0;i<document.ml_list.elements.length;i++) {
    		if (document.ml_list.elements[i].type == "checkbox") {
    			itemName = document.ml_list.elements[i].name;
    			//document.write(itemName);
    			if (itemName.startsWith('ml_message_id')) {
    				this.msgselected = true;
    				this.msgarray[this.msgnum] = document.ml_list.elements[i].name;
    			}
    		}
    	}
    -Mark

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you change
    itemName = document.ml_list.elements[i].name;
    to
    itemName = new java.lang.String(document.ml_list.elements[i].name);
    then itemName.startsWith('ml_message_id') will work - at least in Mozilla


    Or you could use indexOf() instead of startsWith():
    if(itemName.indexOf('ml_message_id') == 0) ...

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by jofa
    If you change
    itemName = document.ml_list.elements[i].name;
    to
    itemName = new java.lang.String(document.ml_list.elements[i].name);
    then itemName.startsWith('ml_message_id') will work - at least in Mozilla


    Or you could use indexOf() instead of startsWith():
    if(itemName.indexOf('ml_message_id') == 0) ...

    oohh...ok, thanks.
    -Mark


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
  •