Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update <input type=text , with JavaScript

Posted on 2000-02-13
2
Medium Priority
?
140 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 200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

773 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