djbuddhi Posted August 22, 2008 Share Posted August 22, 2008 hey guys need help for this example ; this will be entered in a text area item1 | item2 | item3 | item4 | ...etc i want to check after item1 if the user enter | ,if not message will be alert on keypup or keyenter option how to validate this ??? ??? Link to comment https://forums.phpfreaks.com/topic/120808-help-in-java-script/ Share on other sites More sharing options...
cleary1981 Posted August 22, 2008 Share Posted August 22, 2008 Can you give an example of what the items are. Do they contain spaces? If so it will be difficult to see where | should be. Link to comment https://forums.phpfreaks.com/topic/120808-help-in-java-script/#findComment-622831 Share on other sites More sharing options...
djbuddhi Posted August 22, 2008 Author Share Posted August 22, 2008 example : clothes | shipping items | goods | like that only clue is that before submitting the form 2 check whether user enters the '|' mark .thats it how to check string by string in a java script ??? ??? Link to comment https://forums.phpfreaks.com/topic/120808-help-in-java-script/#findComment-622837 Share on other sites More sharing options...
lemmin Posted August 22, 2008 Share Posted August 22, 2008 Since an item can have a space in it, there isn't really a way to check if the user is moving on to the next item, so you can't check for the pipe there. You can check at the end before the form is submitted: <html> <head> <script type="text/javascript"> function validate() { var str = document.getElementById("items"); if (str.value.match(/[\|]/g)) str.form.submit(); else alert("no pipe"); } </script> </head> <body> <form> <input id="items" type="text"> <button onclick="validate()">Submit</button> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/120808-help-in-java-script/#findComment-623054 Share on other sites More sharing options...
djbuddhi Posted August 23, 2008 Author Share Posted August 23, 2008 thanks a lot pal .ur the man ... Link to comment https://forums.phpfreaks.com/topic/120808-help-in-java-script/#findComment-623453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.