#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up How to load value to text field when choose value in select


    Hi every one, I have problem need help that, I have a form have 1 select filed and 1 text field, I want when I choose value in option of select the text field will load/appear value in proportion to value of select, example in picture when I choose "B" in select field, the value in text filed will appear "1", so how to do it, I need example to refer, guide or demo example, Thank for read my topic.

    Here is Image:
    http://i1095(.)photobucket(.)com/albums/i472/OLAKEN91/gdf_zpsac464e04.jpg
    Code:
    Code:
    <head>
    <title>Untitled Document</title>
    <style type="text/css">
    </style>
    </head>
    <body>
    	<center>
        <br />
        <form id="cv" action="" method="">
        	Choose Option: <select id="chedo">
            <option>--Choose Value--</option>
            <option>A</option>
            <option>B</option>
            <option>C</option>
            </select>
            <br />
            <br />
            Value: <input type="text" id="lenh" size="40"/>
            <br />
            <br />
            <input type="submit" value="SUBMIT"/>
        </form>
        </center>
    </body>
    </html>
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,614
    Rep Power
    1945
    You will have to use JavaScript.

    Take a look on how to Get the value of a selected option with Javascript
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    6
    Rep Power
    0

    Thumbs up


    thank for read and help of everyone, here is code

    Code:
    <script type="text/javascript" language="javascript">
    $("#chedo").change(function(){
        var selected = $("#chedo").val();
        $("#lenh").val(selected);
    });
    </script>
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    looks good. But please get rid of the language="javascript" stuff. It's deprecated since a long, long time. Nowadays, we use type.

    If you're using HTML5, you actually don't need any attribute at all, because JavaScript is the default.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,614
    Rep Power
    1945
    Originally Posted by bhb
    thank for read and help of everyone, here is code
    Nice to see you got it working.

    Just remember it can/will be a valuable information if you tell us whether you are using plain JavaScript or a library like JQuery or similar.

IMN logo majestic logo threadwatch logo seochat tools logo