Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 3rd, 2006, 04:38 AM
Authorized User
 
Join Date: Jun 2006
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
 
Old December 3rd, 2006, 05:07 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)





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





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