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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic form validation with Javascript? 16

Status
Not open for further replies.

gbaughma

IS-IT--Management
Staff member
Joined
Nov 21, 2003
Messages
4,773
Location
US
Here's the situation.

I have form web page that is dynamically built from ASP. In other words, the record number is included with the name of the form field, so I could have frm23depart and frm27depart, for example.

I want to do some validation on those fields, but what I need is something like:

function compare(fieldno){
var1=document.form1.frm<fieldno>depart.value;
....

See the issue? I need the javascript to be dynamically passed which FIELD it needs to use for it's calculations

I'm using onchange="compare(<%=fieldno%>)" ... to pass the field number to the javascript.

Any thoughts on this? It's holding up a project that I'm working on.....

I don't really want to dynamically generate multiple functions just for this (although that would be an option).

--Greg


Just my $0.02

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
No reverse checks. This is one of those forms where you get disabled nodes with statements like "This condition goes into effect if you select ANY of the following" or "ALL of the following", followed by the conditions. It can get complicated. Some pages only have two levels. Some have several, and more than one parent node on a particular level. And it's all dynamic.

Yay for recursion!

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs."
-Joseph Weizenbaum
 
Well you get one from me then.

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 

Chrissie.. we can't have you being left out... here's a late gift from Santa...

A smile is worth a thousand kind words. So smile, it's easy! :-)
 
Kyrene said:
The "eval" tag is definitely your friend in a case like this.

Nooooooo! The code you have shown:

Kyrene said:
Code:
var1 = eval("document.form1.frm" + fieldno + "depart.value");

can be done without using eval at all:

Code:
var1 = document.forms['form1'].elements['frm' + fieldno + 'depart'].value;

eval sucks, plain and simple.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Admit it, you just want a star.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
And denial is the first symptom.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
Yeah, it's a definate SW thread! 46 replies and the answer came out twice at practically the same time within 5 minutes of the question being asked!

Oh, well - we can't leave Dan out can we as it was a valid point even if kaht had aleeady pointed it out?! [wink]


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Well, the project is complete. The program I was writing allows people to request a transport, then the transportation supervisor schedules which vehicle, cell phone, driver(s), etc, all the while the form he's using the drop-downs on validates against other scheduled transports using JavaScript (showing a status window of any conflicts), then once he submits the form, it commits it to the database, and adds it to a calendar, which just became the work schedule for the drivers. :)

All in all, I'm pretty proud of it.

Add it to the several hundreds of thousands of lines of code I've ALREADY written at this place... <sigh>

Oh, and I changed my $0.02 :)


Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
Good for you gbaughma, glad you got it all sorted.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
gbaughma said:
Oh, and I changed my $0.02 :)

Well done! Now if you could just convince the other 20-or-so Tek-Tippers who have the same sig-line... ;-)

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Dan,

see above. This little change was a response to 1:00 being "an hour" and not "60 minutes," much the same was as $0.02 is two-one-hundredths-of-a-dollar and 2[&cent;] is two-cents.

It was really just humorous. ...or an attempt anyway.

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Yeah. Take a pill or something, man! Loosen up! :)




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
Take the blue pill and follow the white rabbit.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
Great, Chrissie... Now I'll have Jefferson Airplane going through my head all day!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 
I was thinking of the matrix so you can stop them going round in your head they are there by misstake.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
Let's see... Grace Slick... Keanu Reeves... Grace Slick... Keanu Reeves...

I'll stay with Grace Slick.

Thanks anyway!

Dave


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
O Time, Strength, Cash, and Patience! [infinity]
 

Hey Chrissie, since when did you get your other star ??

You've not been signing on with your alter-ego again have you?

Anyway, it sounds like you've all been taking far too many blue pills if you ask me....



A smile is worth a thousand kind words. So smile, it's easy! :-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top