Jump to content

Help in JAva Script...


djbuddhi

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.