Click to See Complete Forum and Search --> : Drop-down List
hyee1
09-03-2003, 11:58 AM
Hi,
I want to have a drop-down list and when a user selects something out of the list I want the page to be directed at the specific topic the user selected.
I've seen the onClick() where it directs the user to a different page, but what if I want to stay on the same page.
Is this possible?
Thanks...:confused:
You mean a dropdown list that redirects to another page, without loading a different page? That makes no sense. Perhaps, you mean frames?
[J]ona
hyee1
09-03-2003, 12:08 PM
right now this is how my page is...
i have 112 | 113 | 114 and these are links<a href="#112"> so when you click on them it goes directly to the 112, 113 or 114 section on that same page<a name="#112">.
well, now, i have way too many to just list so i wanted to put them in a drop-down list and use the same concept. is that possible?
I'm pretty sure it is. Something like this may work (untested code):
<form action="" name="r_art_frm"><div>
<select size="1" name="art_sel" onChange="eval('location.href='+this.options[this.options.selectedIndex.value]);">
<option value="#">-- Select Article --</option>
<option value="#112">Article 112</option>
<option value="#113">Article 113</option>
<option value="#114">Article 114</option>
</select>
</div></form>
[J]ona
hyee1
09-03-2003, 12:28 PM
so, is 'eval' suppose to be a function written in javascript within the <head> tag?
the links in the drop-down are directing, but it says undefined so i get an error
Khalid Ali
09-03-2003, 12:36 PM
A li'l correction in jonas code above
replace this line
eval('location.href='+this.options[this.options.selectedIndex.value]);
with this one
onchange="location.href=this.options[this.selectedIndex].value"
hyee1
09-03-2003, 12:39 PM
thank you very much...
i have a javascript book, but where do i learn all the functions and methods?
onchange="location.href=this.options[this.selectedIndex].value"
like the above for example... how do you know to write that? i mean is there a reference book or something?
all my book has is the definition about onChange and some code, but not too indepth.
thanks again...
Khalid Ali
09-03-2003, 12:46 PM
oh by the way never use event identifiers like
onChange
always use
onchange
only small letters.
the best place to sink your teeth in js is
www.devedge.netscape.net
Khalid, I'm going to test the cod first next time--I used eval() because I wasn't sure if it would work without it... :P
[J]ona
Khalid Ali
09-03-2003, 01:33 PM
your welcome jona...:)
Tikki
09-03-2003, 01:51 PM
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
mess.Text="You selected " & drop1.SelectedItem.Text
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:DropDownList id="drop1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button Text="Submit" OnClick="submit" runat="server"/>
<p><asp:label id="mess" runat="server"/></p>
</form>
</body>
</html>