View Full Version : regex not matching

05-18-2007, 09:39 PM
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

function checkValue(x)

var list = document.viewMultiple.selectedFiles.value; /**my hidden field**/
var reg = new RegExp(x);
var xyz = "removing "+x;
alert (xyz);
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]

Philip M
05-19-2007, 08:17 AM
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.