Simple Error Checking

Jan 27, 2006

Sorry this will be an ignorant question I know, but I'm just trying to implement some quick JS in my form to check if the fields were filled in:


function check_form() {

if (survey.form_firstname.value == "") {
firstname_error = "-Please enter your first name
";
}

if (survey.form_lastname.value == "") {
lastname_error = "-Please enter your last name
";
}

if (survey.form_phone.value == "") {
phone_error = "-Please enter your phone number
";
}

if (survey.form_email.value == "") {
email_error = "-Please enter your email
";
}

if (!survey.form_agree.checked) {
agree_error = "-You must be over 18 and provide accurate information
";
}

errors = firstname_error + lastname_error + phone_error + email_error + agree_error;

if(!errors) {
return true;
} else {
alert("There were errors:
" + errors);
delete firstname_error;
delete lastname_error;
delete phone_error;
delete email_error;
delete agree_error;
delete errors;
return false;
}
}

It only seems to work if no values are filled in, if one of the fields is filled in the error checking fails. Again, I'm extremely new to JS, i've only ever copy/pasted and this is the first time i've tried writing a piece.

View 2 Replies


ADVERTISEMENT

Hidden Divs And Error Checking

Oct 11, 2005

I have a form that displays various hidden divs if a visitor checks a certain option in my form. For example, if they select Yes in a radio button a few more form fields will appear beneath it. It works fine except when the form is not filled out properly and the form is displayed again (using PHP). When the page reloads it doesn't show the hidden div unless they select No.

how to make it so if they select Yes, it will make the div appear again when the page reloads? Here's the code I'm using: Code:

View 6 Replies View Related

Error Checking And Initialisation In Constructors?

Nov 6, 2011

I'm trying to understand how JS constructors work. In particular, I'm trying to work out how I can call a parameterised constructor and check that the values of the parameters are valid within an object that has private properties. So for test purposes, I construct a data of birth object like this:

HTML Code:
<pre>
function Dob( day, month, year ) {

[code]....

View 4 Replies View Related

Contact Form Error Checking & Validation?

Oct 29, 2010

I'm currently learning many web programming languages and figured this would be a good way to learn more and do things better. I have been working on a contact form for my website. I had originally did the error checking in PHP, but I would like to change it to JaveScript since this is the preferred way. I have it all semi working,It seems like I have some unnecessary variables and such.. I would like to clean it all up as best as possible.

[Code]...

View 3 Replies View Related

Contact Form - Error Checking Not Working On Site

Nov 15, 2010

I made a contact form for my website originally in PHP. I wanted to change it to JavaScript because that is the preferred way. Originally I had the form in my HTML file using a separate PHP file for error checking. For JavaScript do I have to make a separate page and call to it like the last time? I have put it all on my HTML page and where it was calling for the php page, I also put the JavaScript code. When I go to my site, the error checking is not working at all. There must be something wrong, but I haven't been able to point it out and I am very new to JavaScript. Also, when I go to my page and right click for the source code, the JavaScript I have in there does not show up. Below is my HTML code.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]">
<html xmlns="[URL]">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Contact_Form</title>
</head>
<body> .....

View 1 Replies View Related

Getting Nan Error With Simple Math

Mar 5, 2010

why I am getting Nan

<script type="text/javascript">
var num1;
var num2;
var num3;

[Code]....

View 3 Replies View Related

IE Runtime Error On Simple JS Code?

May 21, 2010

I'm getting a runtime error on the code in red. These functions are called by an onBlur by the way.

<script type="text/javascript">
//THIS GENERATES QUANTITY OF MATERIALS
function generate3()

[code]....

View 2 Replies View Related

Simple JSON Callback Error?

Mar 18, 2009

I'm trying to create a "Books I'm Reading" widget using the Readernaut API. I'm using JSON with a callback. This is a portion of what the JSON URL returns:

Code JavaScript:
parseResponse(
{
"version": "1.0", [code]...

View 1 Replies View Related

Remove Element Simple Script Error?

Dec 27, 2009

I am new to Javascript. I copied this script from the web, but I get an error at this line:parent.removeChild(child);The error says "Invalid argument".

<div id="parent" align=center>
<form name=mainfrm method=post>
<script language="JavaScript">

[code]....

View 1 Replies View Related

Simple DHTML Not Working - Syntax Error

Jan 19, 2011

I know I have a simple syntax error. Trying to call a function which changes the style of a div element on mouseover. Heres my code.
Javascript
function countermarker1(){
var box1 = document.getElementById('countermarker1box').style.display
box1 = "block" }
Variable is used cause I will have to use it more often later in the script.

HTML
<div id="countermarker1">
<img src="countermarker.jpg" width="20" height="14"
onmouseover = "countermarker1()"; /></div>
CSS (know its not really relevant just to avoid questions about whether its right)
#countermarker1box {
height: auto;
width: 80px;
display: none;
}
JS and css is externally srced.

View 6 Replies View Related

Simple Calculation - Error On Function Call

Aug 15, 2011

I have written the following javascript code which makes a simple calculation and writes between the <span> tags using Inner HTML

My code is:
Code:
<html><head>
<script type="text/javascript">
function hesapla() {
kredimiktari = document.hesapla.miktar.value
kredivadesi = document.hesapla.vade.value;
faiz = document.hesapla.faiz.value;
ayliktaksit1 = (kredimiktari * faiz) / kredivadesi;
geriodeme1 = kredimiktari * faiz;
document.getElementById('ayliktaksit').innerHTML = "<strong>Taksit / Ay :</strong>" + ayliktaksit1;
document.getElementById('geriodeme').innerHTML = "<strong>Taksit / Ay :</strong>" + geriodeme1;}
</script></head><body>
<form name="hesapla">

<input type="text" name="miktar" value="Kredi Miktarı" onfocus = "if (this.value == 'Kredi Miktarı') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Miktarı';" />
<input type="text" name="vade" value="Kredi Vadesi" onfocus = "if (this.value == 'Kredi Vadesi') this.value = '';" onblur = "if (this.value == '') this.value = 'Kredi Vadesi';" />

<input type="text" name="faiz" value="Faiz Oranı" onfocus = "if (this.value == 'Faiz Oranı') this.value = '';" onblur = "if (this.value == '') this.value = 'Faiz Oranı';" />
<div id="gosterim"><span id="ayliktaksit"></span><span id="geriodeme"></span></div>
<input type='button' value='Hesapla' onClick='hesapla()'><br><br>
<img src="images/dot2.png" width="180" height="2" alt="dot"/>
</form></body></html>

I am really confused as similar code on Tizag web site works fine.
Code:
<script type="text/javascript">
function changeText(){
document.getElementById('boldStuff').innerHTML = 'Fred Flinstone';
}</script>
<p>Welcome to the site <b id='boldStuff'>dude</b> </p>
<input type='button' onclick='changeText()' value='Change Text'/>

View 2 Replies View Related

Simple (simply Irritating) Page Refresh Error In NN

May 22, 2002

I have a VERY simple script to reload a page with fresh values when the value of a scroll menu changes. Trouble is, of course, NN 4.- freaks and closes the browser when this runs. No error warning, no error log?

The line..

<select name="Country" size="1" onChange="repopmenu(this,17)">

The script..
<script language="JavaScript">
<!--
function repopmenu(which,key)
{
n = which.value;
var url = ("eventedit.asp?country=" + n + "&key=" + key)
location.href = url;
}
//-->
</script>

View 2 Replies View Related

JQuery :: Results.push Is Undefined - Getting Error When Trying To Simple Traversing

Mar 29, 2010

I'm getting this error when trying to simple traversing.

results.push.apply( results, checkSet ); jquery-1.4.2.js (line 2743)

I read that it might have something to do with arrays?

View 2 Replies View Related

Simple Error Handling For Form - Avoid Alert Boxes?

Jul 21, 2011

I was trying to create JavaScript error handling for a form, and I was trying to get an error message to show up underneath the field where there was an error. (I am trying to avoid alert boxes.) I only have two fields, and my problem is that only one field is showing an error message. If I place an error in the input for the second field, the error shows up under the first field. How can I get the error messages to show up under the correct form field?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL]">
<html xmlns="[URL]">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
<title>Carrots</title>
<style>
.qty {
width: 25px;
text-align: right;
}.blank {
display: none;
} .....

View 1 Replies View Related

Keep Getting Parse Error : Syntax Error, Unexpected T_STRING In /home/a2460084/public?

Oct 22, 2009

IM NEW AT THIS AND I'M WORKING ON MY FIRST WEBSITE. I USED iWED AND I DON'T UNDERSTAND WHY IT WON'T WORK. WHENEVER I TRY TO OPEN IT IT SAYS: Parse error: syntax error, unexpected T_STRING in /home/a2460084/public_html/beto/index.html on line 1

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">[code].....

View 3 Replies View Related

JQuery :: Get Error Messages To Be Shown In An Error Summary Section Instead Of Inline?

Aug 10, 2009

I'm new to jQuery and the validation plugin, I just wondered if it is possible to get the error messages to be shown in an error summary section instead of inline?

View 1 Replies View Related

Save The Output Xml File, Get Error Permission Denied , Error Code 0?

Jul 18, 2009

I am developing a web page . For this i am using Javascript embedded in html. In the application ,the user can input data via interfaces in the page which is chosen and read from a master xml file , the chosen data then needs to be stored and saved in a xml file.I have designed the web page in FrontPage.

Now the problem i face is while trying to save the output xml file i get error Permission Denied , error code 0 . This happens when i try to open the page in browser IE 6.0 SP2.I am using DOM parser methods for doing the xml manipulations/savings etc.urprisingly this works in another machine.Also can i use the all of the same javascript code if i want to run it in an IIS. Do i have to do some changes to make it server side javascript code.

View 4 Replies View Related

Script Not Defined Error - Firebug Pulls An Error Of DC_ShowDeptStaff Is Undefined

Jul 26, 2010

Trying to use a small bit of script to slide open and closed a div.

Copied it from another page where I have it working just fine. Coding in coldfusion.

When clicked, nothing happens, and firebug pulls an error of DC_ShowDeptStaff is undefined.

Script is:

Code:

Call is:

Code:

Full code is:

Code:

View 5 Replies View Related

Creating Craps Game - After Using The Error Console There's An Error With Document.forms [0].thrower.value Not Being Defined?

Oct 19, 2010

I am working on a simple javascript craps game program. I need some advice since it won't display who the winner is, keep tally of who wins/loses, and the number of total games played. After using the error console there's an error with document.forms [0].thrower.value not being defined.

<html>
<head>
<title> JavaScript Craps Game</title>[code]....

View 13 Replies View Related

Checking Parent's URL ?

Jul 23, 2005

How can i check parent's URL from a child (popup) window ? and how can i
refresh it if the URL is say http://www.xxx.com/?

View 2 Replies View Related

Image Checking

Jan 9, 2006

I have some javascript that uses setInterval(..) to change the src of
an image every second. Is there any way of programmatically checking to
see whether an image is loaded properly or if a 404 File Not Found
error occurs for it?

View 2 Replies View Related

Argument Checking

Aug 8, 2006

Does anyone have any coding rules they follow when doing argument checking?

When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw exceptions?

View 4 Replies View Related

Checking For Null Value?

Jun 18, 2010

I need to check to see if a cookie has been previously created:

var startnum = readCookie('a1');
if (document.cookie.indexOf('a1') == -1){
var startnum = "0";

[code]....

View 5 Replies View Related

Checking For Value Of Text

Jan 4, 2006

I have the following:

<script language="JavaScript">
<!--
window.onload=function (){
var pwinput1 = document.getElementById("tfOtherJobTitle");
pwinput1.onkeyup= function(){
if(this.value = "test"){
document.getElementById("pbRegistration").disabled=false;
}
}
}
</script>

for a button called "pbRegistration" that checks to see if the value of textbox (tfOtherJobTitle) equals "test" and on completion of the typing "test", it enables the button. Why isn't it working?

View 3 Replies View Related

Checkbox Checking...

May 2, 2006

I have a form that produces a few checkboxes via a server side script. Once on the page, the source looks like this...

<tr>
<td><input type="checkbox" name="access" value="1" checked /></td>
<td><input type="checkbox" name="view" value="1" checked
/></td>
</tr>
<tr>
<td><input type="checkbox" name="access" value="2" checked /></td>
<td><input type="checkbox" name="view" value="2" checked
/></td>
</tr>

...what I'm trying to do is pass through the value of the checkbox
ticked through to a function. This function will then, depending on
whether the box is ticked or not, untick the access# checkbox.

I can pass the number through to my function, but I'm having
difficulty trying to reference the actual checkbox from the script.
This is what I've got so far...

function AM_MenuSelection(opt) {
var myOpt=document.frmNew.view[opt].value;
alert(myOpt);
}

As you can see, I can reference the value of the object, but need to
be able to access the related access# object.

View 3 Replies View Related

Checking Next Element

Sep 27, 2006

I'm trying to run some code when a H2 element is clicked on an unordered list below it. The problem is, the code runs whether the h2 has a ul below it or not.

h[x].onclick = function(){
var ul = this.nextSibling;

while (ul.nodeType != 1){
ul = ul.nextSibling;
}

So, if I have something like this:

<h2>Subtitle</h2>
<h2>Subtitle 2</h2>
<ul><li>List</li></ul>

Clicking "Subtitle" runs the function on "Subtitle 2". I don't want the function to run unless the next element is an ul. How can I verify that the next element is an unordered list and if not, don't run anything?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved