Solved

Update <input type=text , with JavaScript

Posted on 2000-02-13
2
133 Views
Last Modified: 2010-04-09
I am trying to update an <inuput type=text object with a value selected from a <select list. My code follows:
<SCRIPT LANGUAGE="JavaScript">
function showit(value) {
   msgbox value
   picked.value=value
}
</SCRIPT>
<form method=POST>
   States
      <select name=state size=3 onchange="showit(this.options[this.selectedIndex].value,this.selectedIndex);">
   <option value="utah">utah
   <option value="newyork">colorado
   <option value="newmexico">new mexico
   </select>
   Picked
 <input type=text name=picked>

The msgbox shows the value selected, but the <input value is not changed. How can I make this process work?
0
Comment
Question by:jc31415
2 Comments
 
LVL 8

Accepted Solution

by:
jbirk earned 50 total points
ID: 2517512
I'm not sure what msgbox is, but try this:

function showit(v) {
msgbox v;
document.formname.picked.value=v;
}


First, it's not a good idea to use a variable named value, since that is already a property used in JavaScript.

To refer to picked properly, it needs to know the object path to get to it. which comes from document, and then the form name.  So you need to specify some name for the form, and then put that in the function above where I put formname.

-Josh
0
 

Author Comment

by:jc31415
ID: 2517594
I had the msgbox line just for testing that I had gotten the right value into the variable.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Page not loading properly 15 40
Paper tearing animation 6 43
lastpass auto fill login form 5 25
Bootstrap 3 icons 3 15
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now