Current location: Hot Scripts Forums » General Web Coding » JavaScript » How can i copy the value from Pulldown menu to Text Box


How can i copy the value from Pulldown menu to Text Box

Reply
  #1 (permalink)  
Old 05-24-04, 04:27 PM
ishaqani ishaqani is offline
Newbie Coder
 
Join Date: May 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
How can i copy the value from Pulldown menu to Text Box

I have the below code with java script. There is a Pull down menu and Text Box, when i select any item from pull down menu, the same value copies in the Text Box. But the Problem is tha when i put the Action form behind these form fields, This script never works I dont know why?? If anyone Knows Some other Technics please tell me.

Please help me in this regards as soon as possible, I would be very much thankfull to you.

Thanks.

Abdul Jabbar


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style></style>
<script language="JavaScript">

<!-- Begin
catnumber = 3
offset = 150
performOnchange = false
if (document.all) {
docObj = "document.all."
styleObj = ".style"
} else {
docObj = "document."
styleObj = ""
}
function closeselect2(submenu,subcat){
popupselect = eval(docObj + subcat + styleObj)
if (submenu.selectedIndex != 0) {
popupselect.visibility = "visible"
numchoice = submenu.selectedIndex
choice = submenu[numchoice].value
data2.value = choice
submenu.selectedIndex = 0
}
}
function closeselect3(submenu,subcat){
popupselect = eval(docObj + subcat + styleObj)
if (submenu.selectedIndex != 0) {
popupselect.visibility = "visible"
numchoice = submenu.selectedIndex
choice = submenu[numchoice].value
data3.value = choice
submenu.selectedIndex = 0
}
}
function lock() {
performOnchange = false
}
function unlock() {
performOnchange = true
}
function selectSub(cat) {
for (i=1; i <= catnumber; i++) {
subcat = "sub" + i
popupselect = eval(docObj + subcat + styleObj)
popupselect.visibility = "visible"
}
if (performOnchange == true) {
letsopen = "sub" + cat.selectedIndex
if (letsopen == "sub0") {
alert("No category selected")
choice = "- subcategory -"
subcategory.value = choice
cat.focus()
} else {
openselect(letsopen)
lock()
}
}
}
// End -->
</script>
</head>

<body>
<!-- TWO STEPS TO INSTALL CATEGORY SELECTION:

1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->
<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->
<div align="center">
<div id="sub2"> </div>
<div id="sub3"> </div>
</div>
<p>
<center>
</center>
<p>
<!-- Script Size: 3.41 KB -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="33%" height="30"> </td>
<td width="33%"><select name="subarts" onChange="closeselect2(this,'sub2')">
<option value="" selected>MENU 1</option>
<option value="music">music </option>
<option value="lyrics">lyrics </option>
<option value="painting">painting </option>
</select></td>
<td width="34%"><select name="subsoftware" onChange="closeselect3(this,'sub3')">
<option value="" selected>MENU 2</option>
<option value="php">php </option>
<option value="java">java </option>
<option value="asp">asp </option>
<option value="mysql">mysql </option>
</select></td>
</tr>
<tr>
<td height="52"> </td>
<td> <input name="data2" type="text" id="data2" value="- subcategory -">
</td>
<td><input name="data3" type="text" id="data3" value="- subcategory -"></td>
</tr>
</table>
<br>
<br>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 05-25-04, 08:13 AM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Use document.getElementById('data2').value = choice instead of just data2.value = choice.
(Same for data3.value)

When you put the form-tag there the reference to the textbox-objects change, so you would have to refer to them using document.formname.data2 or document.forms[form_num].data2.

But if you use document.getElementById() it doesn't matter where they are placed, the script will always find them.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying string array in a text box biohaz25 Visual Basic 2 05-18-04 02:34 AM
text box altafingar Visual Basic 2 05-08-04 10:20 PM
Visual basic text box altafingar Visual Basic 2 04-30-04 08:49 AM
MySQL Query problem Wraith PHP 5 03-06-04 05:16 PM
picking random entries with a filter... Double selection problem dsumpter PHP 7 11-16-03 07:19 PM


All times are GMT -5. The time now is 02:21 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.