Solved

Update <input type=text , with JavaScript

Posted on 2000-02-13
2
135 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

816 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

8 Experts available now in Live!

Get 1:1 Help Now