Question:

How do i put my option value to a textfield the moment i choose a value?

by  |  earlier

0 LIKES UnLike

here is my code:

<input name="type" type="text" disabled="disabled" size="50" value="<?=$type;?>">

<select name="selectType">

<option value="Investor">Investor</option>

<option value="Non-investor">Non-investor</optio...

</select>

i want to put the option value to the textfield every after i selected a new value..

please help

how do i do this?

 Tags:

   Report

1 ANSWERS


  1. You&#039;ll need to use JavaScript. Try something like this:

    &lt;script type=&quot;text/javascript&gt;

    &lt;!--

    function updateField ()

    {

    document.forms[&#039;yourformname&#039;].element... = document.forms[&#039;yourformname&#039;].elements[...

    }

    --&gt;

    &lt;/script&gt;

    Replace yourformname with your form&#039;s name attribute.

    Then, add the onchange attribute to your select, like so:

    &lt;select name=&quot;selectType&quot; onchange=&quot;updateField()&quot;&gt;

    &lt;option value=&quot;Investor&quot;&gt;Investor&lt;/option&gt;

    [and so on]

    &lt;/select&gt;.

    You could also modify it so that your function accepts a field name, like so:

    function updateField (x,y)

    {

    document.forms[&#039;yourformname&#039;].element... = document.forms[&#039;yourformname&#039;].elements[...

    }

    Then your select statement could look like:

    &lt;select name=&quot;selectType&quot; onchange=&quot;updateField(this.name, &#039;YourTextFieldName&#039;)&quot;&gt;

    (replacing YourTextFieldName with the name of the text field

    OR

    &lt;select name=&quot;selectType&quot; onchange=&quot;updateField(&#039;selectType&#039;, &#039;type&#039;)&quot;&gt;

    Hope this helps ;-)

    Note: if the text doesn&#039;t completely display, go to

    http://pcjabber.com/answers/ya_200807211... for the answer.

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.