It's a select, not a textbox. Yours would have done okay with a textbox, hidden, or textarea. For select value, you need to use
var e = document.getElementById("dropdown1"); // select element
var strUser = e.options[e.selectedIndex].value;
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Thanks...but it's still not getting it. I placed an alert after the first line, and it returns null. Than it bombs out on the bottom line. It's a databound listboxe, don't know if that makes a difference? It's bound on pageload.
var e = document.getElementById("lstUser"); // select element
alert(e);
var strUser = e.options[e.selectedIndex].value;
This is the listbox:
<asp:dropdownlist id="lstUser" runat="server" Height="16px" Width="216px" BackColor="#C0C0FF"></asp:dropdownlist>
Ah, yeah, .net changes control names for some things. I'm still learning about that.
You need to register a script block server side and use control.ClientID.
Here's what I use in my datagrid_edit command handler to set focus.
Code:
// set focus to textbox so people don't have to scroll
TextBox txtBox = (TextBox) this.dgRptSpecs.Items[e.Item.ItemIndex].Cells[1].FindControl("rptNameTxt");
RegisterStartupScript("focus", "<script type=\"text/javascript\">\n"+
"Form1." + txtBox.ClientID + ".focus();\n" +
"<" + "/script>");
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Ahhh.....I remember this from before now. .NET changes the client ID. I did vew source on the web page and see that the ID has been changed to "_ctl0_lstUser". When I plugged that in, it works fine.
No problem, but be careful.
It may be dynamically assigned an a per run basis. I'm not sure. I'd check into that before counting on it.
__________________
If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/