File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Validating Dynamic Form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Validating Dynamic Form" Watch "Validating Dynamic Form" New topic
Author

Validating Dynamic Form

Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

I have a Data Entry Form. With many Data Entry fields. I'm using Javascript in two ways. (1) to Validate Data and (2) to manipulate the Form,

I have two fields that relate to each other. I have a drop down box that contains values of 0 thru 24, If user selects anything greater then zero, I use the following code to open up a number of text boxes ( used to enter dates ) the user requested :

var txtbox = document.createElement("input");
txtbox.type = "text";
txtbox.name = "sqDate" + (cellCnt - 1);
txtbox.id = "sqDate" + (cellCnt - 1);
txtbox.value = "mm/dd/ccyy";
cell1.appendChild(txtbox);

In my form (jsp) I have created an empty table <table id="sQmTable" cellspacing="0" border="0" > </table> So the text boxes are created inside this table. This works just the way I want it, but how do I know when the user enters data so I can validate it ? Where would I check for this event ? Would I use "onchange" ? Etc. ?

Thanks for any help
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Please use code tags when posting code


Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

Is it possible to add a variable like below, where my name = sqdate(variable), I know this syntax is incorrect. If this is possible what is the syntax ? Thanks again ( hopefully I used "use code tags" correctly, I tried )

document.addForm1.sqDate(numOfSqmToLoop).value
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Joe Brigs wrote:Is it possible to add a variable like below, where my name = sqdate(variable), I know this syntax is incorrect. If this is possible what is the syntax ? Thanks again ( hopefully I used "use code tags" correctly, I tried )

document.addForm1.sqDate(numOfSqmToLoop).value


Why would you need that??

If you need to pass back the value you can get it with this.value.

Eric
Joe Brigs
Ranch Hand

Joined: Jun 06, 2011
Posts: 60

Eric, my apologies, I don't understand how your 1st response would work. I understand how (this) works , but let me start over. I call the function to create the textboxes when (onchange) the user tells me how many text boxes he wants. I then create the textboxes. I don't want to validate what the user enters in the textboxes until he hits the submit button , so I can validate them all at once. Because I have to check for valid dates but also check for duplicates etc.
I know the name of my textboxes sqDate# ( and I know what the # should be , 1 thru something) . So I wanted to loop thru each one doing the validation and replacing the # with a valid value. Hopefully this explains my problem better. Thanks Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating Dynamic Form