Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-09-2013, 10:59 PM   PM User | #1
thisdesignup
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
thisdesignup is an unknown quantity at this point
Add Alert Message to Form Submit?

So I have this code that I found online that checks if all form elements are filled and only allows the form to be submitted if they are filled. I was thinking I could edit this code to have an alert pop up that would say if the form has been submitted or an alert if the form has not been submitted but I was not able to get it working. Is there anyone here that could help me?

Quote:
<script type="text/javascript">

(function() {
var divs = document.getElementById('ss-form').
getElementsByTagName('div');
var numDivs = divs.length;
for (var j = 0; j < numDivs; j++) {
if (divs[j].className == 'errorbox-bad') {
divs[j].lastChild.firstChild.lastChild.focus();
return;
}
}
for (var i = 0; i < numDivs; i++) {
var div = divs[i];
if (div.className == 'ss-form-entry' &&
div.firstChild &&
div.firstChild.className == 'ss-q-title') {
div.lastChild.focus();
return;
}
}
})();
</script>
I am also not sure if that would be the best way to do it. Preferable I would like to have a red asterisk show up next to the empty fields and have an alert message tell them to look for the red aterick but I don't know enough java script to figure that out.

Is there a way that I could have the javascript check each form element and if it is empty have it show asterick?
thisdesignup is offline   Reply With Quote
Old 01-09-2013, 11:27 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummm...alerts are considered obsolete and bad form and shouldn't be used except maybe for debugging.

Reason: Some browsers no allow users to turn them off. And almost surely all browsers will soon follow suit.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 01-09-2013, 11:47 PM   PM User | #3
thisdesignup
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
thisdesignup is an unknown quantity at this point
So then how might you suggest I go about it? Is it bad to make a fake alert using javascript and css?
thisdesignup is offline   Reply With Quote
Old 01-10-2013, 12:17 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Nope, That would be the right way to do it.

A "popon" <div>, say. That is, a <div> with a z-index higher than the rest of the page but with display: none; in its style. You just put your message inside that div, change the style.display to "block", and there it is. Maybe allow the user to click anywhere in the <div> to change the style.display back to "none".
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:00 AM.


Advertisement
Log in to turn off these ads.