Chocolate570 Posted December 13, 2005 Share Posted December 13, 2005 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 More sharing options...
Jack McKalling Posted December 13, 2005 Share Posted December 13, 2005 It might work in please always stay calm *angel*And to remove the two brackets at the end of the line that defines the onclick attribute *still angel* .....onclick= checkModKey() (remove the red) Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 13, 2005 Author Share Posted December 13, 2005 Thanks Dan, I did, but still, it doesn't work. Is there something wrong with my regexp? Link to comment Share on other sites More sharing options...
Jack McKalling Posted December 14, 2005 Share Posted December 14, 2005 (edited) 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 December 14, 2005 by Dan The Prof Link to comment Share on other sites More sharing options...
hacknsack Posted December 14, 2005 Share Posted December 14, 2005 (edited) 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 December 14, 2005 by hacknsack Link to comment Share on other sites More sharing options...
Chocolate570 Posted December 14, 2005 Author Share Posted December 14, 2005 I fixed it, and it works. The only problem now, is how do I get the selected index of a select box with the attribute "name=mod_options"? Link to comment Share on other sites More sharing options...
hacknsack Posted December 14, 2005 Share Posted December 14, 2005 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 More sharing options...
Chocolate570 Posted December 14, 2005 Author Share Posted December 14, 2005 Thanks so much hacknsack! You're awesome! Link to comment Share on other sites More sharing options...
hacknsack Posted December 15, 2005 Share Posted December 15, 2005 (edited) Glad it was helpful, , just happy to be of service.Thanks, Edited December 15, 2005 by hacknsack Link to comment Share on other sites More sharing options...
Jack McKalling Posted December 15, 2005 Share Posted December 15, 2005 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 More sharing options...
Chocolate570 Posted December 15, 2005 Author Share Posted December 15, 2005 I'm using this on an IF board, so I can't edit those things. Thanks though, i'll try to do it with DOM. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now