473,324 Members | 2,313 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,324 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 1955
<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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.