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 12-09-2012, 09:46 PM   PM User | #1
Drewbun
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Drewbun is an unknown quantity at this point
JavaScript onSubmit event handler not working

The onSubmit event handler is not preventing access to the specified site i want it to go to. I don't know if something is wrong with my function or what. For various reasons im leaving out the site name for now, so please dont think thats the issue. Readers please jump down to the last post, that is where i hit road block. Please Help!

Heres the html

<meta charset="UTF-8" />
<title>Join Here</title>
<script src="../javaScriptFiles/newArtist.js"></script>
<script>
document.createElement("header");
document.createElement("nav");
document.createElement("section");
document.createElement("article");
document.createElement("footer");
document.createElement("aside");
</script>
<link href="../Stylesheets/newArtist.css" rel="stylesheet" type="text/css" />

</head>
<body>
<hgroup>
<h1>New Artist Application Form</h1>
<h2></h2>
</hgroup>
<p>

</p>
<div style="text-align: center;" valign="middle">
<form name="naform" id="naform" action="THIS IS WHERE THE WEBSITE WOULD USUALLY SHOW UP/BUT I LEFT IT OUT"
method="post"
onSubmit="return checkAllTextBoxes();">
<table border="2" style="border-collapse:collapse;width:40%">
<tr>
<td colspan="2">

<label for="firstname">
Artist Actual First Name:</label> <input type="text" name="firstname" id="firstname" placeholder="First Name" required="required" size="20" maxlength="20"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Artist Actual Last Name: <input type="text" name="lastname" id="lastname" placeholder="Last Name" required="required" size="25"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Street Address: <input type="text" name="address" required="required" size="35"/><br>
</td>
</tr>
<tr>
<td colspan="2">
City: <input type="text" name="city" required="required" size="20"/><br>
</td>
</tr>
<tr>
<td colspan="2">
State/Province/Region: <input type="text" name="region" required="required" size="20"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Zip or Mail Code: <input type="text" name="zipcode" required="required" size="15"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Country:
<select name="mydropdown">
<option>Argentina</option>
<option>Australia</option>
<option>Bolivia</option>
<option>Canada</option>
<option>Finland</option>
<option>Kazakhstan</option>
<option>Norway</option>
<option>Russia</option>
<option>Sweden</option>
<option>USA</option>
</select><br>
</td>
</tr>
<tr>
<td colspan="2">
Gender Code:
<select name="mydropdown1">
<option>Yes</option>
<option>No</option>
<option>Not Answered</option>
</select><br>
</td>
</tr>
<tr>
<td colspan="2">
Local Telephone #: <input type="text" name="telephone" required="required" size="15"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Email Address: <input type="text" name="email" required="required" size="40"/><br>
</td>
</tr>
<tr>
<td>
Media in which Artist Works:<br>
<input type="checkbox" name="mediatype" value="Ceramic"/>Ceramic<br>
<input type="checkbox" name="mediatype" value="Fabric"/>Fabric<br>
<input type="checkbox" name="mediatype" value="Glass"/>Glass<br>
<input type="checkbox" name="mediatype" value="Other"/>Other<br>
</td>
<td>
Discount for Quantity?:<br>
<input type="radio" name="discount" value="yes"/>Yes<br>
<input type="radio" name="discount" value="no"/>No<br>
<hr />
Work under prof. name?:<br>
<input type="radio" name="name" value="no" checked />No<br>
<input type="radio" name="name" value="yes"/>Yes<br>
</td>
</tr>
<tr>
<td colspan="2">
Agree to Sell Own Work?<br>
<input type="radio" name="name" value="yes"/>Yes<br>
<input type="radio" name="name" value="no"/>No<br>
</td>
</tr>
<tr>
<td colspan="2">
Password:
<input type="password" name="password" id="password" required="required" size="15"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Password Confirm Repeat:
<input type="password" name="repeatpassword" id="repeatpassword" required="required" size="15"/><br>
</td>
</tr>
<tr>
<td colspan="2">
Brief Artist Biography:<br>
<textarea name="comments" id="biography" cols="70" rows="5" wrap="hard">
</textarea><br>
<tr>
<td colspan="2">
<input type="submit" value="Submit"/>
<input type="reset" action="reset"/>
</td>
</tr>
</table>
</form>
</div>
<br>
<footer>
<div align="center">
<a href="index.html">
<img src="../images/homebutton.gif">
</a>
</div>
</footer>

</body>

</html>


Heres the javascript file:

function checkAllTextBoxes() {

if (document.naform.firstname.value.length <= 1) {
alert("First Name too short--must be at least 2 chars");
document.naform.firstname.focus();
document.naform.firstname.select();
return false; // leave now --block submit
}

}

return true; // if made it to here, all OK--let submit proceed
}

More if statements are going to be added, but i cant get the first stipulation to work, to prevent access to the site. It keeps on bypassing my function. Please help as soon as possible, i have a tight deadline, thanks!

Last edited by Drewbun; 12-10-2012 at 05:35 AM..
Drewbun is offline   Reply With Quote
Old 12-09-2012, 11:41 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
function checkAllTextBoxes() {

if (document.naform.firstname.value.length <= 1) {
alert("First Name too short--must be at least 2 chars");
document.naform.firstname.focus();
document.naform.firstname.select();
return false; // leave now --block submit
}

} <<< this bracket is incorrect/spare, causing the code to fail

return true; // if made it to here, all OK--let submit proceed
}
..because my console told me so!
Attached Thumbnails
Click image for larger version

Name:	error2.png
Views:	21
Size:	35.5 KB
ID:	11782  
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS

Last edited by AndrewGSW; 12-09-2012 at 11:45 PM..
AndrewGSW is offline   Reply With Quote
Users who have thanked AndrewGSW for this post:
Drewbun (12-10-2012)
Old 12-09-2012, 11:52 PM   PM User | #3
Drewbun
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Drewbun is an unknown quantity at this point
changed and still doesnt deny access to linked page

I changed the curly bracket to face the other way and it still doesnt run the function and deny access to the linked page. thanks for your help, but do you have any other suggestions??NVM you were right thanks a ton!

Last edited by Drewbun; 12-10-2012 at 12:19 AM..
Drewbun is offline   Reply With Quote
Old 12-10-2012, 12:23 AM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by Drewbun View Post
I changed the curly bracket to face the other way and it still doesnt run the function and deny access to the linked page. thanks for your help, but do you have any other suggestions??NVM you were right thanks a ton!
It is not necessary to turn a bracket the other way before deleting it
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-10-2012, 04:23 AM   PM User | #5
Drewbun
New to the CF scene

 
Join Date: Dec 2012
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Drewbun is an unknown quantity at this point
javascript not denying access to linked website

My string as i interpret it, is saying i have to enter at least five characters whether they are a letter, a number, or a special character, but when i enter just 1 character the function still allows access to the site. What is going on with my password if statement? Someone please help!


This is the JS library file for newArtist.html page
-------------------------------------------------------*/
/*
The purpose of this function is to go thru the new
artist form and check the content of all the
text boxes for validity. Created yyyy/mm/dd by .
*/

function checkAllTextBoxes() {

if (document.naform.firstname.value.length <= 1) {
alert("First Name too short--must be at least 2 chars");
document.naform.firstname.focus();
document.naform.firstname.select();
return false; // leave now --block submit
}

if (document.naform.lastname.value.length <= 1) {
alert("Last Name too short--must be at least 2 chars");
document.naform.lastname.focus();
document.nafofrm.lastname.select();
return false; // leave now --block submit
}

if (/^\w{5,}$/.test(password)) {
}else {
alert("Invalid Password");
return false;
}



return true; // if made it to here, all OK--let submit proceed
}

Last edited by Drewbun; 12-10-2012 at 04:39 AM..
Drewbun is offline   Reply With Quote
Old 12-10-2012, 09:24 AM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
if (/^\w{5,}$/.test(password.value) ) {


BTW, when posting here please help us to help you by following the posting guidelines and wrapping your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
event handler, javascript, onsubmit, prevent access

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 04:19 PM.


Advertisement
Log in to turn off these ads.