Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email form help needed

Status
Not open for further replies.

trace04

Technical User
Apr 3, 2009
2
US
can anyone please tell me how to add another button called "Find" instead of having the "check button" do everything in my javascript form. I basically want my form to have a user enter their email and have it added, when I click the "check/added" button it checks to make sure the email is entered in the correct format and then adds it. Then the user can enter one letter like "c" and have all emails beginning with "c" show up. The check button will have added the emails and the "Find" will allow me to search for them and then display the results in red where would I place it in my code? I want the search results in green text instead of in the little list that pops up that I have now. So basically I'm looking for help in having an extra "Find" button and changing the way the find results are displayed. I know it doesnt hold data after I close the window but this is what I want. Heres the working form I have now:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Email Address</title>
<script type="text/javascript">

var emails = [];

function checkEmail(inputvalue){
var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
if(pattern.test(inputvalue)){
return true;
}
return false;
}

function addEmail(form) {
var statusBox=document.getElementById('status');
var emailBox = document.getElementById('email_address');
emailBox.style.borderColor = '';
statusBox.style.display='block';
var emailOk = checkEmail(form.email.value);
var found = false;
for(emailIndex in emails) {
if(emails[emailIndex]==form.email.value) {
found = true;
break;
}
}

if(emailOk && !found) {
emails.push(form.email.value);
statusBox.innerHTML = 'Email added.';
statusBox.style.color = 'lime';
}
else {
statusBox.innerHTML = found ? 'Email alread added' : 'Email invalid.';
statusBox.style.color = 'red';
emailBox.style.borderColor = 'red';
emailBox.focus();
}
}

function resetStyle(elId) {
var el=document.getElementById(elId);
el.style.backgroundColor = '';
el.style.borderColor = '';
el.style.color = '';
}

function lookUpEmails(inputBox) {
var suggestBox = document.getElementById('suggest');
var found = false;
suggestBox.innerHTML = '';
for(var emailIndex in emails) {
if(new RegExp('^'+inputBox.value,'i').test(emails[emailIndex])) {
suggestBox.innerHTML += "<div onclick=\"selectEmail('"+emails[emailIndex]+"');\">"+emails[emailIndex]+"</div>";
found = true;
}
}
suggestBox.style.position = 'absolute';
suggestBox.style.top = (inputBox.offsetTop+inputBox.offsetHeight+3)+'px';
suggestBox.style.left = inputBox.offsetLeft+'px';
suggestBox.style.width = inputBox.style.clientWidth+'px';
suggestBox.style.display = found ? 'block' : 'none';
}

function selectEmail(selectedAddress) {
document.getElementById('email_address').value = selectedAddress;
hideBox('suggest');
}

function hideBox(boxId) {
document.getElementById(boxId).style.display = 'none';
}

function init() {
document.onclick=function () {
hideBox('suggest');
}
var emailBox = document.body.getElementById('email_address');
emailBox.onclick = function (e) {
var event = e || event;
e.cancelBubble = true;
return false;
}
}

</script>
</head>
<body onload="init()">
<div id="status">&nbsp;</div>
<form name="signupform" action="#" onsubmit="addEmail(this);return false;">
Input your email: <input name="email" type="text" class="inputs" id="email_address"
value="any@any.com" size="35" maxlength="255" onkeyup="lookUpEmails(this);""><br />
<input name="submit" type="submit" value="Check">
<div id="suggest" style="display: none;border: 1px solid black;">&nbsp;</div>
</form></body></html>

 
Can anyone help? It works now, I just wanted help adding a "Find" button when the user enters the first letter or more of the email addresses their looking for they'll show up in green text instead of a list. Right now the "Check" button searches for the email address and adds them but I only want the "check" button to add the emails.
 
search google for javascript autosearch/autocomplete/autosuggest

there's many such examples, including ones that have xmlhttp, which will poll results from your site so you dont ave to populate your html with emails and even more applicable to check against your DB

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
actually here's one of the google results with a very nice list of suggestions, methods, and styles.


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top