Defining values in a select box on load

liunx

Guest
I am working on a web application and am struggling with the following problem:

When I load a form that has a select box with a list of values in it, the values in the select box don't become defined (meaning, I can't pass the values) until after a user selects off of the default item in the select box.

Any ideas on how to resolve this?Could you possible post the code or URL?yes I am also not sure what your asking. When the page first loads, the value of the select box is set to the "selected" item. The user must select something to change the value.

If you want one of the choices assigned dynamically onLoad of the page, you can use some server side magic to assist you.I apologize. I didn't make much sense because it seems to be a long explanation, but here goes:

I have a select box which is automatically populated with values from a query. EXCEPT for the initial value which is always "New".

I set this form up so that when the user selects on an item in the select box, the item's properties populate the text fields I have provided (such as Name, etc). This is done via the ONCHANGE attribute. So, when the user clicks on another item in the select box, the form is submitted and the values in the text boxes change to the properties associated with the selected value.

What I am struggling with is this: whenever the user selects an item in the select box, the form.selectboxname is a valid variable, meaning that it exists. So, whenever I select on a new item, the variable form.selectboxname changes to the value of the selected item. The problem is that when I load the form, I would like the variable form.selectboxname exist for the "New" item. Instead, when I enter the form, this variable does not exist UNTIL I select on an item in the select box. What I want is for this varialbe to exist when the user loads the form. I want the variable set to the "New" value for form.selectboxname.

I use ColdFusion for this and will probably post this message in the CF forum as this might be more applicable to that forum instead. However, if anyone has an idea, please let me know.

Thanks!

Here's the portion of the code that is applicable:

<FORM NAME="FORMNAME" ACTION="FORMNAME">
<SELECT NAME="NameList" SIZE="5" STYLE="width:470" onChange="SubmitMe()">
<OPTION VALUE="New"<CFIF NOT IsDefined ("form.NameList")> selected</cfif>
>NEW
<CFOUTPUT QUERY="qNames">
<OPTION VALUE="#qNames.name#"
<CFIF IsDefined ("form.NameList")>
<CFIF #qNames.name# EQ #form.NameList#>
SELECTED>
</CFIF>
</CFOUTPUT>I do the same thing in coldfusion. I pass in something through the URL, or through a query. Your using a query, so try something like .....


<cfquery name="name of query" datasource="datasourceName" dbtype="ODBC" username="username" password="password">
select * from tablename
</cfquery>

(do you have a field for what was selected? If so just evaluate it on render of the data...)

<form>
<select name=select>
<option name="<cfoutput>#nameofquery.idfield#</cfoutput>" <cfif #nameofquery.selecetedfield# is "yes">selected<cfelse><!---nothing---></cfif>><cfoutput>#nameofquery.datafieldname#</cfoutput></option>
</select>


if you need more stimulous, let me know.Thanks for the idea. I'll give it a go.
 
Back
Top