HighDots Forums  

JavaScript - How to add preset values to form input forselect box

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss JavaScript - How to add preset values to form input forselect box in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
jasals
 
Posts: n/a

Default JavaScript - How to add preset values to form input forselect box - 11-09-2005 , 08:12 AM






I want to allow users to inout a production date and then have a slect box
below that uses that inout value to calculate 2, 3, and 6 month end point dates
all on the same form. Can some one show me how? I regualrly code in HTML and
Cold Fusion, but am not so hot on JS techniques - usually find sample online
and edit to suit - couldn't find anything for this one.

I would imagine an onblur action from the text input field that sets values
for the select box - much like related select, I guess... just need some
assistance getting it set up.

Thanks!


Reply With Quote
  #2  
Old   
rilkesf
 
Posts: n/a

Default Re: JavaScript - How to add preset values to form inputfor select box - 11-10-2005 , 01:15 PM






Jonathan,

Probably several ways to do this, but here's one. Note that in this example
the <form> is named 'testform' and the <select> is named 'newdate'. The
entered date takes the form of M/D/YYYY with no need for leading zeros on
single digit months and days.

Hope it helps.

Javascript code (triggered onBlur of the text field):



function update() {
var newdates = Array(2,3,6);
for(i=0; i<newdates.length; i++) {
var date = document.testform.date.value;
var splits = date.split('/');
splits[0] = newdates[i] + eval(splits[0]);
if(splits[0] > 12) {
splits[0] = splits[0] - 12;
splits[2] = eval(splits[2]) + 1;
}
var reformed_date = splits[0] + '/' + splits[1] + '/' + splits[2];
document.testform.newdate.options[i] = new Option(reformed_date,
reformed_date);
}
}


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.