Click to See Complete Forum and Search --> : Automatic updating of field


Padrill
05-14-2003, 09:28 AM
I'm using a script similar to the auto-year (http://javascript.internet.com/forms/auto-year.html)
from javascript.internet.com to create a drop down menu for selecting the year (of a date). I have this script in an external .js file and use it for many different pages.

Does anyone have any ideas on how can I have it update a field when the users makes a selection? Something similar to the onChange="updateField()" function.

pyro
05-14-2003, 09:37 AM
What exactly do you need to do? Why not just run a function onchange, as you said?

Padrill
05-14-2003, 09:53 AM
Instead of copying the HTML code for a drop down menu that has 100 options in every page I just call a function (eg. dropDownYear();) that creates the menu. Now I need to update a field on certain pages according to the selection. Is that any clearer?

pyro
05-14-2003, 10:00 AM
Well, you could get the selected index of the option menu, like this:

document.formname.selectname.options[document.formname.selectname.selectedIndex].value

Padrill
05-14-2003, 10:04 AM
Sorry my fault: I need to update the field when a selection is made.

pyro
05-14-2003, 10:07 AM
Then you will need to use an onchange command...

Padrill
05-14-2003, 10:20 AM
If I put an onChange command in the script (which is in the functions.js file) like this

document.write('<select name="year" onChange="doSomething();">');

Then every menu I create using this function will always try to doSomething when the user makes a selection and I only want this to happening for one menu.

Padrill
05-14-2003, 10:38 AM
I found the solution myself thanx to sanjayv earlier post.