Text Box Value from drop box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Text Box Value from drop box

Post 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
jmaker
Forum Newbie
Posts: 16
Joined: Tue May 21, 2002 11:13 pm

Re: Text Box Value from drop box

Post 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>
 
Post Reply