Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting focus on dropdown changed 2

Status
Not open for further replies.

boatdrinks

IS-IT--Management
Jun 18, 2004
51
US
I know this is wrong, I am trying to set the text 'DTP' appear in textbox insertbarcde only if index 1 is selectedfrom dropdown inserthardware. How should this code look?


<SCRIPT LANGUAGE=javascript>
<!--
function OnChange(dropdown)
{
var myindex = inserthardware.selectedIndex
If myindex == 1

insertbarcode.Attributes.Add("onfocus",@"if (this.value == '') {this.value = 'DTP';}";
end if;
return true;
}
//-->
 
Something like this:

Code:
<SCRIPT LANGUAGE=javascript>
<!--
function OnChange(si) {
  var t = document.forms['formname'].elements['insertbarcode'];
  if (si == 1)
    t.value =( t.value == '') ? 'DTP' : t.value;
}
//-->

And then:

Code:
<select name="blah" onchange="onChange(this.selectedIndex);">

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Thanks I tried it and it says object expected when i select the dropdown
 
Did you change 'formname' to the actual name of your form?

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Also the function declaration is OnChange but you are calling it as onChange from the select.

You need to use exactly the same case.

--James
 
Yes here it is

<SCRIPT LANGUAGE=javascript>
<!--
function OnChange(si) {
var t = document.forms['form1'].elements['insertbarcode'];
if (si == 1)
t.value =( t.value == '') ? 'DTP' : t.value;
}
//-->
</SCRIPT>
 
nice catch james.

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Here is the dropdown

<asp:DropDownList onselectedindexchanged="barcodevalidate" id="inserthardware" width="175" onchange="onChange(this.selectedIndex);" viewstate="true" autopostback="true" runat="server">
 
James most likely nailed the problem on the head. Do this:

Code:
<asp:DropDownList onselectedindexchanged="barcodevalidate" id="inserthardware" width="175" onchange="[red]O[/red]nChange(this.selectedIndex);" viewstate="true" autopostback="true" runat="server">

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
No prob.

*cLFlaVA
----------------------------
"Holy crip he's a crapple!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top