Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics 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 1st, 2004, 10:01 AM
Authorized User
 
Join Date: Nov 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default On change listbox

I have a listbox with 5 choice, I would like that if the user choose 1 particular word, it automatically link to a new page but does'nt do anything special if he choose any of the 4 others one.

Is it possible.

Thank you

Johnjohn

 
Old December 1st, 2004, 10:23 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

You can do this with JavaScript.

Let the select box name be cboChoices and the form name be frmOptionSelector. The sample code for doing this is :

<script Language="JavaScript">
    function funcRedirect()
    {
        if(document.frmOptionSelector.cboChoices.options[document.frmOptionSelector.cboChoices.selectedInde x].text=="<the option text which redirects to a different page>")
        {
            window.location="<the page to which the visitor is to be redirected>";
        }
    }
</script>

Then call the function funcRedirect in the onChange event of cboChoices.

Hope that helps.
 
Old December 1st, 2004, 11:10 AM
Authorized User
 
Join Date: Nov 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you but maybe I don't understand something because it don't work, see my code. Thank you very much again.

<HTML>
<BODY>

<FORM METHOD='GET' ACTION='Test1.asp' NAME='frmOptionSelector' >

<SELECT NAME = 'cboChoices' onchange = 'funcRedirect()' >
<OPTION> the one
<OPTION> dude
<OPTION> UPDATE
</SELECT>

</FORM>


<script Language="JavaScript">
function funcRedirect()
{
    if(document.frmOptionSelector.cboChoices.options[document.frmOptionSelector.cboChoices.selectedInde x].text=="<UPDATE>")
    {
        window.location="<test2.asp>";
    }
}
</script>

</BODY>
</HTML>


 
Old December 1st, 2004, 06:22 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

johnjohn

COMMENTS:
1..Functions must have trailing semi-colons:
funcRedirect() = wrong
funcRedirect(); = correct
2..There is a very big difference between:
<UPDATE> and UPDATE
3..Same as above for:
<test2.asp> and test2.asp

IMO:
1..<option> tags should have a closing </option> tag
2..Almost all JS functions code should be in the head of your document
3..This post is better suited in the JS forum

This will work for you:

-----------------------cut n paste---------------------
<HTML>
<head>
<title></title>
<script Language="JavaScript">
function funcRedirect()
{
    if(document.frmOptionSelector.cboChoices.options[document.frmOptionSelector.cboChoices.selectedInde x].text=="UPDATE")
    {
        window.location="test2.asp";
    }
}
</script>
</head>
<BODY>
<FORM METHOD="GET" ACTION="Test1.asp" NAME="frmOptionSelector">
<SELECT NAME="cboChoices" onchange="funcRedirect();">
<OPTION>the one</option>
<OPTION>dude</option>
<OPTION>UPDATE</option>
</SELECT>
</FORM>
</BODY>
</HTML>
--------------------finish cut n paste----------------------

Wind is your friend
Matt
 
Old December 2nd, 2004, 12:51 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

What Matthew gave will work correctly.

Please do not send personal mails about the issues that are being discussed here.

Hope you won't get offended.

Cheers

Madhu





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Listbox sarah lee ASP.NET 2.0 Basics 2 May 15th, 2007 02:09 PM
Change color of text in a listbox? ja8261 VB.NET 2002/2003 Basics 11 April 27th, 2007 10:14 AM
Change the ForeColor in a ListBox?? thomaz C# 0 November 23rd, 2006 01:35 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





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