Results 1 to 6 of 6

Thread: Adding valuess from a drop down list to a textbox

  1. #1
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Adding valuess from a drop down list to a textbox

    I have the following script which adds values from a drop down list to a textbox.

    Code:
    <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

  2. #2
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    If you had an onchange event in the drop down list that called a function like this

    HTML Code:
    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

  3. #3
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks for your help.

    Unfortunately I am unable to get the script to work.

    Code:
    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

  4. #4
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    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.

  5. #5
    Join Date
    Feb 2009
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <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
    Code:
    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
    Code:
    onChange="dothis(this.form,this)"

  6. #6
    Join Date
    Apr 2009
    Location
    Cognac, France
    Posts
    400
    Thanks
    2
    Thanked 57 Times in 57 Posts

    Default

    Have you put in an alert to see what formname is set to.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •