Reputation: 307
Just wondering if anybody knows any tutorials or scripts where I can get form notifications.
Pretty much what I want is when someone types in particular keywords in a form then it needs to come up with a message.
What I want to do is when a viewer types in the following keywords into a form;
Medlab Central
Medlab Wanganui
Naylor Lawrence
Doughboys Bakery Limited – owners surname ‘Funke’
Denver Stockfeeds Limited – owners surname ‘Currie’
Midland Civil Limited – Miles and Vicky Worsley
Arran Trust – Stephen and Mary Barr
Roadmarking Services Limited – Karen and Kelly halligan
Steeds Pharmacy Ltd
I want a notification to popup saying 'There may be a conflict of interest. Please wait to hear from Proa regarding how they can help'
Had a quick go, is this the correct coding for HTML;
<form id="theForm">
<input type="text" />
<input type="submit" value="Send Email">
</form>
</body>
<script>
var specialWords = ["hello", "goodbye"];
$(function(){
$('#theForm').on("change keyup", "input[type='text']", function(event){
var inputValue = $(this).val();
if($.inArray(inputValue, specialWords) > -1){
alert(inputValue + " is a special word!");
}
});
});
</script>
</html>
I have found a script that works..
<script language="JavaScript">
var nav=navigator.appName;
var ns=(nav.indexOf("Netscape")!=-1);
if(ns){
if(document.layers){
document.captureEvents(Event.KEYPRESS);
document.onkeypress = cheat;
}
if(document.getElementById){
document.onkeypress = cheat;
}
}
else
{document.onkeypress = cheat;}
var SpecialWords = "here"
var SpecialLetter = 0;
var vcheat = false
function cheat(keyStroke)
{
var eventChooser = (ns)?keyStroke.which: event.keyCode;
var which = String.fromCharCode(eventChooser).toLowerCase();
if(which == SpecialWord.charAt(SpecialLetter)){
SpecialLetter++;
if (SpecialLetter == SpecialWord.length) alert("There may be a conflict of interest. Please wait to hear from PROA regarding how they can help")
}
else {SpecialLetter = 0;vcheat = false}
}
</script>
however I now need it to work for multiple specialwords. I tried to do what Mark said which was
var specialWords = ["hello", "goodbye"];
but wouldnt work . any suggestions.
Upvotes: 0
Views: 1523
Reputation: 10217
A good resource on the standard Javascript pop-ups is: http://www.w3schools.com/js/js_popup.asp. Some people don't like them because you can't apply custom styling to them and are synchronous (the browser can't do anything until the pop-up is removed) but they are simple to use and do get the users attention!
I'm not sure exactly what what you want, but the following example code might be of help - it triggers an alert when the user types "hello" or "goodbye" into a text field (just change the values in the array as required!). Here I'm assuming the mark up contains the following:
<form id="theForm">
<input type="text" />
</form>
Then the following jquery code should do it:
var specialWords = ["hello", "goodbye"];
$(function(){
$('#theForm').on("change keyup", "input[type='text']", function(event){
var inputValue = $(this).val();
if($.inArray(inputValue, specialWords) > -1){
alert("There may be a conflict of interest...");
}
});
});
Edit: note that jquery's on
function is as of version 1.7, if you're using an older version, try looking at live
or delegate
.
Upvotes: 1
Reputation: 4197
As you have tagged jquery i would assume a plugin like jquery validate
http://archive.plugins.jquery.com/project/validate
Demo is included at the bottom of the page.
Upvotes: 1