Skip to main content
Inspiring
September 8, 2006
Question

Dynamic dropdown based on user selection of another dropdown on the same page

  • September 8, 2006
  • 7 replies
  • 713 views
hi all, ok, I have a table which contains use data, a name, and a userID. for the example lets say "Simon Bullen" and my userID is "999".
on a form I have, there is a dropdown box, which is dynamic from this table, and allows me to select Simon Bullen, however, I have a hidden field on the form, which when the user selects "simon bullen" the hidden field populates with the appropiate U number from the same table.... no i thought this would do it:

<cfquery name="userNumber" datasource="userList">
SELECT userNumber FROM dbo.Users WHERE Name =
<cfqueryparam value="#form.Name#">
</cfquery>

and then my dynamic form field (hidden) would reference to this query....

but it doens't work, could somebody please enlighten me? I'm hoping its something silly

I am using DW8, CF7 and SQL

Thanks in advance
    This topic has been closed for replies.

    7 replies

    Inspiring
    September 17, 2006
    very strange indeed... you have a username AND user id already, and you want users to select their username and then select their user id... or even pre-select it for them... "why like this?", as a good friend of mine used to put it
    please care to enlighten us about the, apparently hidden, logic of this? very intrigueing.... can't wait to find out. i am sure we all would be able to suggest a better way for you to go about whatever you are trying to achieve.
    the only possible need for any of this i can think of is if the username and userid data in your db is totally unrelated, but defines the same person....
    Inspiring
    September 15, 2006
    Sorry for the tardy reply....been away for work.

    The question begs to be asked.....if you already have the username/user_id details somewhere, why are you asking for them again? If you have this info in a db already, you're much better off using the db to do this kind of work for you, rather than the browser.
    Inspiring
    September 12, 2006
    Ok....now I'm confused too. Simon, in your first post, you mention you're trying to update a hidden form field, but in your second post you say it's a drop down box. Which one is it and what, exactly, are you trying to achieve?
    Inspiring
    September 12, 2006
    ok, sorry everyone for making it confusing; this is what I am trying to acheieve;

    I would like the user to populate my database with thier username AND userID. I have a dropdown box with thier username dynamicly populated already, what I am trying to achieve, is a way of when the user selects thier username either another dropdown or a hidden field is automatically populated with the appropiate userID (to match thier username). Now I could just have two dropdowns and they select both, but i'd rather avoid the possibility of mismatches, and that is why I would like it to be automatic and based on thier username selection...

    Does that make sense....?
    Inspiring
    September 8, 2006
    It sounds like you want something on the server to dynamically change a page while it is still in the browser window. The only way to do that is by using AJAX.

    It seems to me that all you need to do is set the userID as the value for your select box and just display the name.

    <OPTION VALUE="999">Simon Bullen</OPTION>

    No reason to use a hidden field for this.
    Inspiring
    September 11, 2006
    quote:

    Originally posted by: dempster
    It sounds like you want something on the server to dynamically change a page while it is still in the browser window. The only way to do that is by using AJAX.


    Wrong. You can use wddx. Check out this thread for more info on that.
    Inspiring
    September 11, 2006
    Whether you use AJAX or wddx and JavaScript, my main point is that it doesn't seem to make any sense if I understand the original question. If you want to see a name in the select box but get the value of the user ID number, you should just use the value parameter in the option tag.
    September 8, 2006
    No problem dude, wasn't having a go at you!

    There are many ways to do this. You can do it with JS and CF although CF is probably more secure as JS could be disabled.

    It's amazing what google can find...check this...

    http://projects.nateweiss.com/nwdc/workcode.htm

    It's a custom tag. I havn't used it or even read it, just found it and post it here within two secs. Sounds like it does the Job though.

    Good luck.
    Inspiring
    September 8, 2006
    apologies for the multiple messages, I can't seem to delete them though

    ok, my aim is. If I select "Simon Bullen" on dropdown box 1, dropdown box 2 will automaticlly be populated with my matching "userID" from the same Database...

    hope that makes sense
    September 8, 2006
    What exactly are you trying to achieve? It doesn't make sense. Oh and if you can, could you please delete your duplicate posts.

    Cheers.