Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AJAX Combo Validation

Status
Not open for further replies.

rhnewfie

Programmer
Joined
Jun 14, 2001
Messages
267
Location
CA
I have a combo box that I loaded via AJAX, when I submit my form the name/value pair gets transmitted just fine but when i try to do client side validation via javascript it doesn't get the value.

var obj = document.formname.element;

if (obj.value == '')
{
...
}

Is there some special method to this or will it simply not work?

Thanks!
 
You're really going to have to be more specific than that..... The code you posted is about as generic as it comes. We can't pull any detail from what you provided so it's impossible to give you a detailed answer. Do you have a link to this application that we can test ourselves?


-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
Actually I don't and unfortunately it is not live yet or on an accessible server.

In my asp page I have a div named combodiv1 into which the combo loads named combo1. My form is called form1.

Now, when I submit the form combo1 and it's selected value get passed with the form data but on submission I call a validate() function, all other fields validate properly (those written into the form from the base asp page) but the javascript can't seem to access the combo1 that was dynamically inserted via AJAX.

So, when I do

var obj = document.form1.combo1;

I get nothing.

Unfortunately I dont have access to my code right now. I will grab something to put up here later.

Thanks
 
Is it only inserting 1 combo box? Will that combo box be unique? If so, try giving it and id in addition to it's name, and then use document.getElementById("combo1") to access it instead of using the form collection. Additionally, you could also try using complete syntax for accessing the collection: document.forms["form1"].elements["combo1"]

That doesn't really answer why your code isn't working, but without seeing it I would be hard pressed to pinpoint your exact problem.

-kaht

Looking for a puppy?

silky-icon-left.gif
[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
silky-icon-right.gif
 
I will try the id value and access it that way. Sorry that I can't post anything right now but will get back to this tonight.

It is unique though, if that helps.

I will let you know how it works out.
 
as kaht said the best way to access ajax'd form fields is via document.getElementById("combo1")
 
AJAX'd... I like that :-D
 
Well, I got to my office and looked at my code and realized I'm an idiot. The validation for the combo that I was looking for was simply

if (!document.form.combo2)
{
...some message
}
else
{
validate combo selection
}

basically if they have not selected a value in the combo1 then the second combo that I have to validate doesn't even exist yet... hasn't been AJAX'd

Sigh...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top