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

Adding fields dynamically using JavaScript 1

Status
Not open for further replies.

n4s

Programmer
Nov 20, 2002
11
NZ
Can any one help me ? I need help in two areas of JavaScript.

One:-
Using JavaScipt I need to add couple of Text fields, Dropdown Lists, and Buttons dynamically in my application. And at the same time I need to do client side validations on those fields.

Two:-
I have two date fields (Text fields) in dd/mm/yyyy format. Among these two dates, one field value must be always > other. (Date1.value > Date2.value)


I am just familier with JavaScript but not good. Please help me.

Thank you,
SAHI.
 
wow!!! i cant give u a script to create things dynamically, but what u need is DOM(Document Object Module). search for it...

Known is handfull, Unknown is worldfull
 
Easy way is to load all fields but have the optional ones hidden by default. Only on a certain condition do they show up. You can combine JavaScript and Styles for this.

You can always have an onchange event written for both the date fields and check them when either of them changes.

Cheers!
Roy
 
For validation of the dates:

Code:
function compareDates()
{
 var date1 = form1.date1.value.split('/');
 var date2 = form1.date2.value.split('/');
 var year1 = parseInt(date1[2]);
 var year2 = parseInt(date2[2]);
 if(year1 < year2)
  return true; 
 else if (year1 > year2)
  return false;
 else
 {
  var month1 = parseInt(date1[1]);
  var month2 = parseInt(date2[1]);
  if(month1 < month2)
   return true;
  else if(month1 > month2)
   return false;
  else
  {
   var day1 = parseInt(date1[0]);
   var day2 = parseInt(date2[0]);
   if(day1 < day2)
    return true;
   else if(day1 > day2)
    return false;
   else
    return true; //or 'false' depending on what you 
                 // want to see when dates are equal
  }//end else
 }//end else
}//end compareDates()

'hope that helps!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top