473,288 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,288 software developers and data experts.

display option in a textbox

//I have a form such as this:
echo "<form method=\"post\" action=$php_self>
<BR><INPUT TYPE=\"TEXT\" NAME=\"textbox\" SIZE=\"40\">
<BR> <select name=\"searchlist\">
<option value=\"val1\">$x</option>
<option value=\"val2\">$y</option>
<option value=\"val3\">$z</option>
<option value=\"val4\">$t</option>
</select> <p>
<input type=\"submit\" name=\"submit_the_values\" value=\"$submit\">
</form><p>";

/* I want that the option selected in the "searchlist" option get
displayed in my textbox using javascript, how can I do this? thanx in
advance pat */
Jul 23 '05 #1
4 1952
<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
//I have a form such as this:
echo "<form method=\"post\" action=$php_self>
<BR><INPUT TYPE=\"TEXT\" NAME=\"textbox\" SIZE=\"40\">
<BR> <select name=\"searchlist\">
<option value=\"val1\">$x</option>
<option value=\"val2\">$y</option>
<option value=\"val3\">$z</option>
<option value=\"val4\">$t</option>
</select> <p>
<input type=\"submit\" name=\"submit_the_values\" value=\"$submit\">
</form><p>";

/* I want that the option selected in the "searchlist" option get
displayed in my textbox using javascript, how can I do this? thanx in
advance pat */


<html>
<head>
<title>opt2txt.htm</title>
<script type="text/javascript">
function opt2txt(that) {
var what = that.options[that.selectedIndex].value;
document.forms[0].textbox.value = what;
}
</script>
</head>
<body>
<form method="post" action="$php_self">
<br>
<input type="text" name="textbox" size="40">
<br>
<select name="searchlist" onchange="opt2txt(this)">
<option value=""></option>
<option value="val2">$y</option>
<option value="val3">$z</option>
<option value="val4">$t</option>
</select>
<p>
<input type="submit" name="submit_the_values" value="$submit">
</form>
<p>
</body>
</html>

I added <option value=""></option> so "onchange" would detect a choice.
Jul 23 '05 #2
McKirahan wrote:
<ki*********@yahoo.com> wrote in message
news:39**************************@posting.google.c om...
<--snip-->
function opt2txt(that) {
var what = that.options[that.selectedIndex].value;
document.forms[0].textbox.value = what;


The last line refers explicitly to the first form in the document - so
add another form above this one and the script either fails or updates
the wrong field.

The syntax for "textbox" is also not cross-browser (it may work in IE,
but certainly doesn't work in Geko browsers). How about:

that.form.elements['textbox'].value = what;

This fixes the syntax and references the calling form based on the
element that fired the script rather than its position in the DOM
(presuming, of course, that the textbox really is in the same form as
the event that fired the script).

Cheers.
Jul 23 '05 #3
thanx a lot Rob. it works great :)
Jul 23 '05 #4
ki*********@yahoo.com wrote:
thanx a lot Rob. it works great :)


That's OK.

Incidentally, I lied about the syntax for:

that.form.textbox.value = what;

it will work fine in Geko browsers, I got confused with IE
allowing id's to be used as global variables. But in any
case,

that.form.elements['textbox'].value = what;

is the preferred syntax.
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Targa | last post by:
I have a select box with about 5 options. I need to have one of the options, when selected, display a second select box. The second select box is populated by a database and needs to be preloaded...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
1
by: Tom | last post by:
Hi I want to display the DB data in a tabcontrol. There is a textbox insides that tabcontrol <code private void Bind_DBData( string strSql = "select * from table WHERE id > 0 order by id"...
4
by: Milan | last post by:
Hi, I am having a problem with displaying a * to a required field. There seems to be a problem with this and the static value does not appear unless you submit the page. I am trying to display...
2
by: Nowezo | last post by:
Hi, Can you please help me, I want to write a dropdown box that have an option 'Other' but when the Other is selected my textbox need to be enable and take the textbox value as an output instead of...
3
by: remya1000 | last post by:
i'm using ASP with MSAccess as database. i have two buttons and two textbox in my page. when i press my first button (First month) i need to display the current month in one textbox and last one...
13
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log...
7
by: TechnoAtif | last post by:
Hi..There is again a similar problem..Now i;ve got the option values of list?menu box to show the textbox. If the option value of list is yes then the textbox is to be displayed . Can anyone...
1
by: angelicdevil | last post by:
i have listbox 1 which displays status , based on selection of status listbox 2 displays usernames. and based on username selected the textbox displays the email id. its working fine till...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.