Jump to content

Matching


Chocolate570
 Share

Recommended Posts

Ok, i've spent the last few daqys avoiding my computer. Sad isn't it. (there's a point here.) Do you want to know why? I CANT GET THIS STUPID SCRIPT TO WORK! AHHH!I'm done.Basically, what the script does is get the value of a textarea, then checks if it contains a phrase. What I want it to do is check for multiple phrases, but that's a different story. Currently, my regxp doesn't work, and my match() doesn't work. Can anyone tell me what the heck i'm doing wrong?

<script type="text/javascript">////////////////////////////////////////*PostMOD Script NEAY(not even alpha yet)©Chocolate570 2005Editing anything could resultin faliure of execution(the thing might blow up)*///////////////////////////////////////if(document.REPLIER){  document.REPLIER.submit.onclick= checkModKey();}function checkModKey(){  re=/test/g  PostVal  = document.REPLIER.Post.value;  if(PostVal.match(re))  {    alert(PostVal);    return false;  }}</script>

Link to comment
Share on other sites

Maybe it would work if you didn't put the match criteria in a variable but direct in the match, and if you wrote both gi flags? :)

if(PostVal.match(/test/gi))...
Edit: You can't save insensitive things in a variable, so that is just the problem you have :(By the way, you haven't used regexp yet :) Edited by Dan The Prof
Link to comment
Share on other sites

Choco,I'm not sure if you are trying to disable the form or not, maybe an idea for you here..Also included example of how you can use "new RegExp()" to create the re.

<html>  <head>  <meta http-equiv="content-type" content="text/html; charset=windows-1250">  <title></title>  <script type="text/javascript">  var word = 'test';  //  \b looks for word boundary  var re = new RegExp("\\b" + word + "\\b","gi");  alert(re);    function chgForm(){  document.forms['REPLIER'].elements['submit'].onmouseover = ckPost;  }    function ckPost(){  var field = document.forms['REPLIER'].elements['Post'];  var found = field.value.match(re);  if(found){    alert('Word found in post..');   setTimeout("document.forms['REPLIER'].elements['Post'].focus();", 50);   } }  window.onload = chgForm;  </script>  </head>  <body>  <form name="REPLIER">    <textarea name="Post" rows="6" cols="20"></textarea>    <input name="submit" type="submit">  </form>  </body></html>

Good Luck,

Edited by hacknsack
Link to comment
Share on other sites

You can capture that like this:

  <script type="text/javascript">  function getSel(){  var selObj = document.forms["f1"].elements["mod_options"];    alert(selObj.selectedIndex);    alert(selObj.options[selObj.selectedIndex].value);  }  </script>  </head>  <body>  <form name="f1">    <select name="mod_options" onchange="getSel()">      <option value="">Pick One</option>      <option value="1">1</option>      <option value="2">2</option>    </select>  </form>

Thanks, :)

Link to comment
Share on other sites

Just a notice,I would add these reds to the code to have the header option not chosable :)

<script type="text/javascript"> function getSel(Value){ var selObj = document.forms["f1"].elements["mod_options"];  if (Value) {   alert(selObj.selectedIndex);   alert(selObj.options[selObj.selectedIndex].value); }} </script> </head> <body> <form name="f1">   <select name="mod_options" onchange="getSel('this.value')">     <option>Pick One</option>     <option value="1">1</option>     <option value="2">2</option>   </select> </form>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...