Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 3rd, 2006, 04:38 AM
Authorized User
 
Join Date: Jun 2006
Location: BANGALORE, Karnatak, India.
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ajit
Default Combobox problem

Hi, I have a combobox and a hidden field. When combobox value is changed, I am storing the text value of combobox in the hidden field, below are those to fields
Code:
<input type="hidden" name="strPrinterName"/>

<select name="cboPrinterName" onClick="fnSetPrinterName()">
<%=objLoadCombo.loadAvailablePrintersCombo()%>
</select>
This combo boxes option values are generated by a bean.


OnClick() event of the combobox i have called a javascrpt function fnSetPrinterName(), Below is the function implementaion,
Code:
var frmName = document.forms[0];
function fnSetPrinterName(){
gfnCopyCBTextToOtherElt(frmName.cboPrinterName,frmName.strPrinterName);
}
The function internally calles another function gfnCopyCBTextToOtherElt(), that takes combobox and hidden field through the parameter, Below is the function implementaion.
Code:
function gfnCopyCBTextToOtherElt(strCBName,strOtherElt){
var strList = frmName.elements[strCBName.name];
if(strList.selectedIndex!=null)
frmName.elements[strOtherElt.name].value 
= strList.options[strList.selectedIndex].text;
}
The above function worked well for other sets of combobox-hidden field combinations. But This one case its giving error in function gfnCopyCBTextToOtherElt(strCBName,strOtherElt),

The line of code where the error occured is
Code:
frmName.elements[strOtherElt.name].value = strList.options[strList.selectedIndex].text;
The error is "Object does not support this property or method."


Ajit
__________________
Ajit
Reply With Quote
  #2 (permalink)  
Old December 3rd, 2006, 05:07 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Perhaps you should try using onchange rather than onclick in the select element.
Your code seems a little complicated for a simple task. Why not:
Code:
<input type="hidden" name="strPrinterName"/>

<select name="cboPrinterName" onchange="fnSetPrinterName()">
<%=objLoadCombo.loadAvailablePrintersCombo()%>
</select>
fnSetPrinterName()
{
  var frm = document.forms[0];
  var iIndex = frm.cboPrinterName.selectedIndex;
  if (iIndex > -1)
  {
    frm.strPrinterName.value = frm.cboPrinterName.options[iIndex].text;
  }
}
--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox Problem sfl234 C# 2 January 6th, 2007 01:22 PM
Problem in ComboBox Tayyab326 ASP.NET 1.0 and 1.1 Professional 0 November 15th, 2006 03:03 AM
c# comboBox Initialization problem ColdFusion ASP.NET 2.0 Basics 1 May 11th, 2006 12:44 PM
problem about combobox nucharee General .NET 2 October 1st, 2004 04:05 AM
ComboBox problem chacquard Access 2 September 10th, 2004 11:40 AM



All times are GMT -4. The time now is 04:57 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.