[Pro] Javascript - check if value contains

I’m checking if a form field string ‘contains’ a certain value as opposed to checking the ‘exact’ value

Anyone know the correct way in Javascript?

 {
  var frm = document.forms["myform"];
  if(frm.FirstName.value == 'Bob')
  {
    sfm_show_error_msg("Bob, you can't submit this form. Go away! ");
    return false;
  }
  else
  {
    return true;
  }
}

dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

That’s correct as long as your form has an id of myForm. If not, and
it’s the only form on the page you can use (unchecked):

document.forms[0].FirstName.value

Joe

On 7 Sep 2009, at 15:56, WebWorker wrote:

I’m checking if a form field string ‘contains’ a certain value as
opposed to checking the ‘exact’ value

Anyone know the correct way in Javascript?

{
var frm = document.forms["myform"];
if(frm.FirstName.value == 'Bob')
{
  sfm_show_error_msg("Bob, you can't submit this form. Go away! ");
  return false;
}
else
{
  return true;
}

}


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry, Maybe I did not make myself clear enough.

This check if the name “is” bob…

 {
  var frm = document.forms["myform"];
  if(frm.FirstName.value == 'Bob')
  {
    sfm_show_error_msg("Bob, you can't submit this form. Go away! ");
   return false;
  }
  else
  {
return true;

}
}

I want to check if the whole string “frm.formfeild.value” contains the word “http://” anywhere in it? I want to “not” include any “http://” in a form field


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

I would use indexOf;
if(frm.FirstName.value.indexOf(“Bob”) > -1) /* is Bob in there
anywhere? /
or
if(frm.FirstName.value.indexOf(“Bob”) == 0) /
does the value
start with Bob? */
Regards,
Tim.

On 8 Sep 2009, at 09:36, WebWorker wrote:

Sorry, Maybe I did not make myself clear enough.

This check if the name “is” bob…

{
 var frm = document.forms["myform"];
 if(frm.FirstName.value == 'Bob')
 {
   sfm_show_error_msg("Bob, you can't submit this form. Go away!  

");
return false;
}
else
{
return true;
}
}

I want to check if the whole string “frm.formfeild.value” contains
the word “http://” anywhere in it? I want to “not” include any
“http://” in a form field

FreewayActions.com - Freeware and shareware actions for Freeway
Express & Pro.

Protect your mailto links from being harvested by spambots with Anti
Spam.
Only available at FreewayActions.com

http://www.freewayactions.com


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Sorry, I just assumed you couldn’t get that block of code working, my
mistake.

On 8 Sep 2009, at 09:55, Tim Plumb wrote:

I would use indexOf;
if(frm.FirstName.value.indexOf(“Bob”) > -1) /* is Bob in there
anywhere? /
or
if(frm.FirstName.value.indexOf(“Bob”) == 0) /
does the value
start with Bob? */
Regards,
Tim.

Yep, or match() which returns null if not found, so you can use:

if(frm.FirstName.value.match("Bob"))

Joe


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options

Thanks Joe and Tim - much appreciated


dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options