Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 16th Oct 2012, 04:24 AM   #1
Warrior Member
War Room Member
 
Join Date: 2011
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default
JavaScript Validation Alert
Share on: 
fb share twitter share gplus share more share

Hi Warriors!

I am trying to validate a JS form without getting the alert to show up as a pop up on the page. I want the alert to be displayed inline with the webpage. I believe we need to use 'innerHtml' syntax but I am not sure how.

Also this is there anyway to make the form accept the coupon code in lower case?

Here's my code:


<html>
<head>
<title>Coupon code</title>
<script type="text/javascript">
function isValid(){ var coupon = document.getElementById('coupon').value;
if (coupon == "25OFF")
{alert('Coupon code has been applied.')}
else {alert('Invalid coupon code')} }
</script>
</head>
<body>
<form name="couponField" action="">
Coupon code: <input type="coupon" id="coupon" name="coupon"> <input type="button" value="Apply Coupon Code" onclick="isValid();"> </form> </body> </html>

Below is the code for the effect (the sliding button) that I am trying to achieve:

<html>
<head>
<title>Coupon code</title>
<script type='text/javascript'>
function notEmpty(elem, helperMsg){
var valid = false; if(elem.value.length == 0){ document.getElementById('errorMessage').innerHTML = helperMsg; elem.focus(); }
else{
valid = true; }
return valid; }
</script>
</head>
<body>
<form action='something.php' method='POST' onsubmit="return notEmpty(document.getElementById('coup'), 'Please Enter a Valid Coupon Number')">
Coupon Code:&nbsp;<input TYPE = "text" NAME = "coupon field" id='coup' SIZE = "20" VALUE = ""/>
<span id='errorMessage'></span>
<input type="submit" value="Apply coupon code"/> </form>
</body>
</html>

Thanks in advance for your help!
a7521 is offline  
Unread 1st Nov 2012, 06:08 AM   #2
Warrior Member
 
Join Date: 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: JavaScript Validation Alert
Share on: 
fb share twitter share gplus share more share

JavaScript Validation Alert a way to validate form's data on the client's computer before sending it to the web server. There are two types of validation
1. Basic Validation
- First checked to make sure data was entered into each form field that required it.2.Data Format Validation - Data that is entered must be checked for correct form and value.

chongbscott is offline  
Closed Thread


Bookmarks

Tags
alert, javascript, validation


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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 09:44 AM.