473,325 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Form Validation Problem

LacrosseB0ss
113 100+
hey all. I am having a problem with a form on a php page. The form has a selection box on it and that box will obviously have items in it. I'm trying to test whether or not something was selected when a button is clicked or the item to be selected is doubleclicked on. The code looks like this:

function onDoubleClick(){
var index = document.forms.main_form.Emp;
var value = document.forms.main_form.Emp[index.selectedIndex].value;

if (value == "")
{
alert("Select an Employee");
}else{
if ( exist(value, fullname) ){
alert(fullname + " already on the list");
}else{
addEmployee(value, fullname);
}
}
}

The problem is with the initial 'if' statement. Does anyone know what it should read? Everything else works fine but when nothing is selected, an exception is thrown by Javascript. I would rather have a message box displayed.

Sorry if this sounds basic, before inheiriting the project, I had not worked much with javascript nor php. I'm learning as I go but this one is driving me nuts.

Thanks!
Oct 12 '06 #1
4 1108
stnick
11
I believe the word "value" that you are using as a variable is a reserved word.
Change it to something like strValue and try that instead.

~nicholas
Oct 13 '06 #2
LacrosseB0ss
113 100+
doi! I should've clued into that. I've changed both value to strValue and index to strIndex but I'm still getting the same error.

When nothing is selected from a listbox and "Add" button is clicked (to add an employee to a list), the following error is produced:

***************************************
Line: 2757
Char: 3
Error: Object Doesn't Support this Property or Method
Code: 0
***************************************

My problem isn't names or types or any of that. The problem is the code uses document.forms, which I have never seen before, to select the listbox (named Emp). Is there a way to check if something has been selected using Emp.selectedIndex or Emp.value? (see above code again)

Thanks for the previous reply and to anyone else in advance for any help provided.
Oct 13 '06 #3
LacrosseB0ss
113 100+
I should also mention, so far I have tried value = null, value == null, value = "" and value == "". I've also tried the same thing with index as the variable (with changed names). I believe that runs me out of options (which is why I decided to come here...)

TIA again

Also worthy of noting: I discovered when index and value are entered into variables, they are in object form. Is there some kind of casting/parsing I can do to fix this? Or how do I simply check an object? Thanks!
Oct 13 '06 #4
LacrosseB0ss
113 100+
Ok, so apparently I was wrong. The problem(s) are occuring in the 2 lines:

var fullname = document.forms.main_form.Emp[selIndex.selectedIndex].text;
var value = document.forms.main_form.Emp[index.selectedIndex].value;

Apparently the unsupported property/method here is ".text" and ".value". Does anyone out there in superScriptingKnowledge Land know what it should be?

Thanks! (sorry for changing my questions AGAIN)
Oct 13 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
6
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
7
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.