PDA

View Full Version : Adding valuess from a drop down list to a textbox



Macca
05-13-2009, 10:38 AM
I have the following script which adds values from a drop down list to a textbox.


<script type="text/javascript">
document.forms['NameOfForm'].elements['List'].onchange = function(){
document.forms['NameOfForm'].elements['Textbox'].value += this.value + ' ';
};
</script>

Does anyone know of another way to do this without having to call the name of the form? having to re-do one of my forms in Oracle9ias Portal and the way forms are set-up the above script will not work as the name of the form changes by session IDs.

thanks

forum_amnesiac
05-13-2009, 11:30 AM
If you had an onchange event in the drop down list that called a function like this


onchange="dothis(this.form,this)"

Your function would be like this

function dothis(form, field){
formname=form.name;
fieldname=field.name;
document.formname.Textbox.value += this.value + ' ';
}

Something like this, have a play

Macca
05-14-2009, 10:08 AM
Thanks for your help.

Unfortunately I am unable to get the script to work.


formname=form.name;
fieldname=field.name;

As I mentioned I cant call the form name as this changes each time the page is loaded. I take it the fieldname is the drop down list?

thanks again

forum_amnesiac
05-14-2009, 01:38 PM
Yes the field name applies to the name that you give, eg <select name="myField" onChange="dothis(this.form,this)">

The function dothis() returns the name of the field and the form.

Do not change the names inside the () for the function, leave them as this.form and this.

Even if the form has a different name each time it is run/refreshed the function should return the name of the form.

Post your full code, or a link so that it can be looked at.

Macca
05-15-2009, 02:05 PM
<script type="text/javascript">
function dothis(form, field){
formname=form.name;
fieldname='CHARGEREQUEST.DEFAULT.CHARGE_TAGS.01';
document.formname.'CHARGEREQUEST.DEFAULT.CHARGE_TEXT_STYLE.01'.value += this.value + ' ';
}
</script>

I have tried different ways for this function to work without success. As I mentioned the form has been re-designed in Oracle Portal 9ias. The name of the drop down list is called 'CHARGEREQUEST.DEFAULT.CHARGE_TAGS.01. Can't change the name as it's automatically set. Wrapping '' around the text works for
fieldname='CHARGEREQUEST.DEFAULT.CHARGE_TAGS.01'; but not the last part. As always grateful for any advice.

I have also set the drop down list with
onChange="dothis(this.form,this)"

forum_amnesiac
05-15-2009, 04:44 PM
Have you put in an alert to see what formname is set to.