Page 1 of 1

Text Box Value from drop box

Posted: Thu Oct 01, 2009 4:52 pm
by nite4000
Hey everyone.

I am having a lil trouble here I am on the right track but just not making it here anyway... What I want to do it this.

I have a drop box

Code: Select all

<select name="meth" id="meth">
          <option value="select" selected="selected">Select </option>
          <option value="ap">Alert Pay</option>
          <option value="stp">Solid Trust Pay</option>
          <option value="cp">Compound</option>
        </select>
and I have a textbox

Code: Select all

<input name="acc" type="text" size="35" maxlength="50">
now with selecting each option I need to have a value of the text box reflect. ex. if AlertPay is selected then value in text box would be alertpay and same with stp however with coupound would be different.

I need to hide the textbox above and 1 other one and replace it with another text box.

I hope i have explained it good I am unsure myself.


Thanks

Re: Text Box Value from drop box

Posted: Thu Oct 01, 2009 5:27 pm
by jmaker
I hope this is what you're looking for. It's pretty simple and it just uses a little bit of javascript. Whatever you select, that option's value will be displayed in the text box.

Code: Select all

 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>title</title>
        <link rel="stylesheet" href="/css/master.css" type="text/css" media="screen" title="no title" charset="utf-8" />
        <script type="text/javascript" charset="utf-8">
            function changeText(obj) {
                document.getElementById("acc").value = obj.value;
            }
        </script>
    </head>
    <body>
        <form name="form" id="money" method="post" action="">
         <select name="meth" id="meth" onChange="changeText(this)">
          <option value="select" selected="selected">Select </option>
          <option value="ap">Alert Pay</option>
          <option value="stp">Solid Trust Pay</option>
          <option value="cp">Compound</option>
         </select>
        </form>
        
         <input name="acc" type="text" size="35" maxlength="50" id="acc">
 
    </body>
</html>