Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

auto select with select box

Explorer ,
Jan 19, 2009 Jan 19, 2009
Hi

I have a site which has 8 services.each service has it own page. When the user goes to the service page there will be a link which will take them to a form. I want the form to be able to identify which service is there and select that one automatically.

I have done this previously but only with a form. Can you please help me to fix this.

Link on service page <a href="moreinfo.cfm?service=WorkGroup Consultancy">Click here for Further Information</a>

select box in form <select name="service">

<option value="UK Immigration" <cfif structKeyExists(form,"UK Immigration") AND form.service eq "WorkGroup Consultancy">selected="selected"</cfif>>UK Immigration</option>
<option <cfif structKeyExists(form,"WorkGroup Consultancy") AND form.service eq "WorkGroup Consultancy">selected="selected"</cfif>value="WorkGroup Consultancy">WorkGroup Consultancy</option>
<option value="Legal Managment Software" <cfif structKeyExists(form,"Legal Managment Software") AND form.service eq "Legal Managment Software">selected="selected"</cfif>>Legal Managment Software</option>
<option value="Search Engine Optimization" <cfif structKeyExists(form,"Search Engine Optimization") AND form.service eq "Search Engine Optimization">selected="selected"</cfif>>Search Engine Optimization</option>
<option value="Marketing Consultancy" <cfif structKeyExists(form,"Marketing Consultancy") AND form.service eq "Marketing Consultancy">selected="selected"</cfif>>Marketing Consultancy</option>
<option value="Project Management" <cfif structKeyExists(form,"Project Management") AND form.service eq "Project Management">selected="selected"</cfif>>Project Management</option>
<option value="Training" <cfif structKeyExists(form,"Training") AND form.service eq "Training">selected="selected"</cfif>>Training</option>
<option value="Web Design"<cfif structKeyExists(form,"Web Design") AND form.service eq "Web Design">selected="selected"</cfif>>Web Design</option>


</select>
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 19, 2009 Jan 19, 2009
<cfselect selected="#url.service#">
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 19, 2009 Jan 19, 2009
Your original code looked pretty close to working. The one thing you had wrong is the variable scope - when you pass a parameter via a URL variable (e.g. moreinfo.cfm?service=WorkGroup Consultancy) the resulting variable on the action page of the form will be in the URL scope, not the FORM scope. If you were to pass the variable as a hidden form field instead of a URL query parameter your code would work (from first glance, that is).
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2009 Jan 21, 2009
I have tried both was and still cannot get it to work. Please shwo me the correct way to do this



<cfselect name="service" selected="#url.service#">
<option value="UK Immigration" >UK Immigration</option>
<option value="WorkGroup Consultancy">WorkGroup Consultancy</option>
<option value="Legal Managment Software" >Legal Managment Software</option>
<option value="Search Engine Optimization" >Search Engine Optimization</option>
<option value="Marketing Consultancy" >Marketing Consultancy</option>
<option value="Project Management">Project Management</option>
<option value="Training" >Training</option>
<option value="Web Design">Web Design</option>
</cfselect>


And the other way
option value="UK Immigration" <cfif structKeyExists(URL,"UK Immigration") AND url.service eq "WorkGroup Consultancy">selected="selected"</cfif>>UK Immigration</option>
<option <cfif structKeyExists(url,"WorkGroup Consultancy") AND url.service eq "WorkGroup Consultancy">selected="selected"</cfif>value="WorkGroup Consultancy">WorkGroup Consultancy</option>
<option value="Legal Managment Software" <cfif structKeyExists(url,"Legal Managment Software") AND url.service eq "Legal Managment Software">selected="selected"</cfif>>Legal Managment Software</option>
<option value="Search Engine Optimization" <cfif structKeyExists(url,"Search Engine Optimization") AND url.service eq "Search Engine Optimization">selected="selected"</cfif>>Search Engine Optimization</option>
<option value="Marketing Consultancy" <cfif structKeyExists(url,"Marketing Consultancy") AND url.service eq "Marketing Consultancy">selected="selected"</cfif>>Marketing Consultancy</option>
<option value="Project Management" <cfif structKeyExists(url,"Project Management") AND url.service eq "Project Management">selected="selected"</cfif>>Project Management</option>
<option value="Training" <cfif structKeyExists(url,"Training") AND url.service eq "Training">selected="selected"</cfif>>Training</option>
<option value="Web Design"<cfif structKeyExists(url,"Web Design") AND url.service eq "Web Design">selected="selected"</cfif>>Web Design</option>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2009 Jan 21, 2009
What was the value of url.service when the cfselect method did not work?

In your second method, are you sure that you have url variables named UK Immigration, WorkGroup Consultancy, etc?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2009 Jan 21, 2009
Yeah. I have the following code on each services

<a href="moreinfo.cfm?service=Search Engine Optimization">Click here for Further Information</a>
<a href="moreinfo.cfm?service=Training">Click here for Further Information</a>
<a href="moreinfo.cfm?service=Project Management">Click here for Further Information</a>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2009 Jan 21, 2009
With those url variables, your structkeyexists functions will return false 100% of the time.

For the selected="#url.service#" method, you are probably experiencing difficulty because of the spaces. Try it with Training. That's only 1 word.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2009 Jan 21, 2009
I thought the spaces may have caused a problem but even when i take them out i am still getting the same problem. Any other suggestions
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 21, 2009 Jan 21, 2009
I never code it the way you do, so I tried it. This won't work:
<cfform action="abc.cfm" method="post">
<cfselect name="abc" selected="two">

<option value="one">one</option>
<option value="two">two</option>
</cfselect>
</cfform>

This will
<cfscript>
MyQuery = QueryNew("field1", "varchar");
x = QueryAddRow(MyQuery, 2);
x = QuerySetCell(MyQuery, "field1","one", 1);
x = QuerySetCell(MyQuery, "field1","two", 2);
</cfscript>
<cfform action="abc.cfm" method="post">
<cfselect name="abc" query="MyQuery" value="field1" display="field1" selected="two"></cfselect>
</cfform>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 21, 2009 Jan 21, 2009
LATEST
Thanks that works great just changed selected="two" to selected="'#service#" and it works perfect
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources