Skip to main content
July 2, 2009
Question

cfselect to a link

  • July 2, 2009
  • 2 replies
  • 918 views

i have a cfselect drop down box with 4 options.

i also have a link next to the cfselect drop down.

now once i made a selection on the cfselect box i want pass that value as a parameter to link. how can i do that. here is the code sample...

<cfselect name="DirecotryOrder" >
            <option value="lastname">Last Name</option>
            <option value="firstname">First Name</option>
            <option value="nickname">Nick Name</option>
            <option value="dept">Department</option>
            </cfselect>
                  
   
           
            <a href="print-directory.cfm?id={filtercol.selecteditem.data}" > Link </a>

any help is apriciated...

    This topic has been closed for replies.

    2 replies

    Known Participant
    July 2, 2009

    Simplest way:

         <a href="#" onclick="location.href = 'print-directory.cfm?id=' + document.forms[0].DirecotryOrder.value"> Link </a>

    -or-

         <a href="#" onclick="location.href = 'print-directory.cfm?id=' + document.getElementById('DirecotryOrder').value"> Link </a>

    I don't like it, but if your looking for quick solutions... that will do; you shouldn't do onlicks on href - but apperently most devs around the net don't really care. I like the DIV idea .

    Buzzi.

    Inspiring
    July 2, 2009

    If you want to use that approach, you could make it <a href="javascript etc">.  It's probably simpler than the div.

    Known Participant
    July 3, 2009

    No.  <a href="javascript:... is outdated, you NEVER use that since that’s being phased out by newer browsers, and guess what? It will get to a point that it won’t work. Don’t EVER do that. A better solution is onclick and ... I dislike that too, but that at least is still within standards.

    Buzzi

    Inspiring
    July 2, 2009

    Put the link in a <div>.   Write some javascript to change the value of that div when the value of the select changes.

    Just out of curiousity, is the cfselect part of a form that can be submitted to a page that's not print-directory.cfm?

    July 2, 2009

    yes, cfselect is a part of the form. form also has a grid. when i post it back,  it will not populate the "form" contents. it just refreshes the grid. this was done by some one else...i am trying add some things and make it work....i tried to just create a button and post it when the user submits. and the based the form contents i can direct the flow. but thats it not working....i am not sure how the grid will impact the form posting...