By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Listbox value in the textbox

P: 20
Hello all
I have one list box ans text box on my site, lik this:

Expand|Select|Wrap|Line Numbers
  1. <select name="lstScript">
  2. <option>Javascript</option>
  3. <option>VBscript</option>
  4. <option>PHP</option>
  5. <option>Actionscript</option>
  6. <option>Other</option>
  7. </select>
  8.  
  9. <input type="text" id="txtScript" readonly="yes" />
When I click on the item 1 from the list box (lstScript) I'de like to see the value "Javascript" in the text box so I add a script function:

Expand|Select|Wrap|Line Numbers
  1.  <select name="lstScript"   onchange="txtScript.value = lstScript.vlaue" >
  2.   ...
  3.   </select>
But it doens't work like this, any suggestion or experience to solve this pleas?
Jan 27 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 428
do not start identifiers with digits- 1stvalue is invalid.
You also need to set values to read them.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  2. <html lang= "en">
  3. <head>
  4. <meta http-equiv= "Content-Type" content="text/html; charset=utf-8">
  5. <title>first script</title>
  6. <script type= "text/javascript">
  7. onload= function(){
  8.     var sel= document.getElementsByName('selectScript')[0];
  9.     var inp= document.getElementsByName('txtScript')[0];
  10.     sel.onchange= function(){
  11.         inp.value= sel.value;
  12.     }
  13. }
  14. </script>
  15. </head>
  16. <body>
  17. <h1>First Script</h1>
  18. <form action="" onsubmit="return false">
  19. <p>
  20. <select name= "selectScript" size="1">
  21. <option selected= "selected" value="Javascript">Javascript</option>
  22. <option value= "VBscript">VBscript</option>
  23. <option value= "Other">Other</option>
  24. </select>
  25. <input type= "text" name="txtScript" readonly="readonly">
  26. </p>
  27. </form>
  28. </body>
  29. </html>
Jan 27 '08 #2

P: 20
do not start identifiers with digits- 1stvalue is invalid.
You also need to set values to read them.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  2. <html lang= "en">
  3. <head>
  4. <meta http-equiv= "Content-Type" content="text/html; charset=utf-8">
  5. <title>first script</title>
  6. <script type= "text/javascript">
  7. onload= function(){
  8.     var sel= document.getElementsByName('selectScript')[0];
  9.     var inp= document.getElementsByName('txtScript')[0];
  10.     sel.onchange= function(){
  11.         inp.value= sel.value;
  12.     }
  13. }
  14. </script>
  15. </head>
  16. <body>
  17. <h1>First Script</h1>
  18. <form action="" onsubmit="return false">
  19. <p>
  20. <select name= "selectScript" size="1">
  21. <option selected= "selected" value="Javascript">Javascript</option>
  22. <option value= "VBscript">VBscript</option>
  23. <option value= "Other">Other</option>
  24. </select>
  25. <input type= "text" name="txtScript" readonly="readonly">
  26. </p>
  27. </form>
  28. </body>
  29. </html>
Thanks you very much ..

best regards
Jan 27 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.