Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    regex not matching

    I have (0-many) checkboxes outside of a form.
    When one checkbox is selected I want to updated a hidden field inside the form to include that checkbox, so I know they are checked. I am using * as the delimiter.
    similarly when they are unchecked, I would like to remove them from the list.
    However, the code seems to only append once to the hidden field, and then after that, it always be evaluating the reg.test(list) part to be true, so it tries to remove the checkbox name.

    x is the name of the checkbox that the user has just clicked

    Code:
    function checkValue(x)
    {
    	
    	var list = document.viewMultiple.selectedFiles.value; /**my hidden field**/
    	var reg = new RegExp(x);
    	if(reg.test(list)){
    		list.replace(reg,"");
    		var xyz = "removing "+x;
    		alert (xyz);
    	}else{
    		var newVar = document.viewMultiple.selectedFiles.value+x+"*";
    		document.viewMultiple.selectedFiles.value = newVar;
    		alert (newVar );		
    	}
    }
    I think the problem may be the checkbox names.
    Here is an example of the checkbox name:
    gi|121612266|ref|YP_999723.1| hypothetical proteinCJJ81176_0030 [Campylobacter jejuni subsp. jejuni 81-176]
    Last edited by bluegirl; 05-18-2007 at 09:41 PM. Reason: changed quote to code

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Seems a complicated way of going about things.

    I have the idea that your problem is the * which in a regex signifies match zero or more occurances, i.e is a meta character.

    For example, /we*/ matches "w" in "why" and "wee" in "between". /x*/ will always return true.


  •  

    Posting Permissions

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