> what is the problem with this piece of code:
>
> i want to navigate to diff forms depending on value in listbox.
>
> <cfform name="main_menu1" method="POST">
>
> <cfselect name="select" size=1 multiple="No">
> <option value="0" selected>none
> <option value ="2">employee
> <option value="3">customer
> </cfselect>
>
> <cfif "form.select" is "2">
> <cflocation url="employee.cfm">
> <cfelseif "form.select" is "3">
> <cflocation url="customer.cfm">
> </cfif>
>
> </cfform>

The problem with this is that the CFML code executes on the server before
the HTML form is sent to the client. Form variables only exist after a form
has been posted to the server, and are then available in the action page.
So, you could do something like this:

<!-- form.cfm -->
<html>
<head>
<title>Form</title>
</head>
<body>
<form action="formaction.cfm" method="post">
        <select name="myselect">
                <option value="0">none
                <option value="1">employee
                <option value="2">customer
        </select>
        <input type="submit">
</form>
</body>
</html>

<!-- formaction.cfm -->
<cfif form.myselect is "1">
        <cflocation url="employee.cfm">
<cfelseif form.myselect is "2">
        <cflocation url="customer.cfm">
</cfif>

Note that this requires two trips to the server; one to retrieve the form,
and one to process the form submission. You could do something with
JavaScript instead which would be more efficient.

There was another problem which I should point out. In your conditional
logic, you did this:

> <cfif "form.select" is "2">

If you wrap something in quotes, it's a literal string, rather than a
variable. You could do this:

<cfif "#form.select#" is "2">

which would evaluate the variable within the literal string. Or, better yet,
you could do this:

<cfif form.select is 2>

which doesn't require any evaluation.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

------------------------------------------------------------------------------
Archives: http://www.eGroups.com/list/cf-talk
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to