Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Populating drop down menus and direction on form coding

    So this is the deal. Three weeks ago I began learning javascript because I was given the job at the company I work for. My project is to finish the website they've spent the last five years working on. This website consists of, among other things, several forms with lots and lots of drop down menus. Right now these drop down menus are populated using tons of individually defined variables and very very long if() else statements.

    I've read the shortening if() statements page in the faq and it was super helpful. Now I'm trying to find a way to make populating these drop down menus less of a chore. I've been learning about loops, arrays and objects from Jon Duckett's book javascript and jquery and I see a lot of potential, but I don't know what will work best and since I'm being paid to work I don't want to waist a bunch of time trying things if they aren't going to work the way I think they will.

    My idea (no code yet, and I don't expect anybody to provide any here) is to use a loop to cycle through an array that holds a complete list of drop down menu items for each question and remove items from that array based on the other questions.

    Will this work? Also, any suggestions you guys have for things I can start studying that will make writing form code easier would be awesome.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,996
    Thanks
    79
    Thanked 4,433 Times in 4,398 Posts
    Quote Originally Posted by David801 View Post
    My idea (no code yet, and I don't expect anybody to provide any here) is to use a loop to cycle through an array that holds a complete list of drop down menu items for each question and remove items from that array based on the other questions.

    Will this work? Also, any suggestions you guys have for things I can start studying that will make writing form code easier would be awesome.
    It's really tough for us to guess what will work best for you without knowing the details of the needed application.

    Personally, I would have thought that the best choice might be putting the drop-down choices into a DB and then building the page (say using PHP) by making a SQL query to the DB.

    It's not clear to me why you would use JavaScript to create the <select>s in the first place. Does <select name="two"> depend on what the user chose in <select name="one">??? Or similar?

    If the <form> contents depend on changes made within the same <form>, then yes, JS will be the way to go. But even then I might consider using AJAX and DB queries to get the <select> contents.

    If the <form> contends depend on *PRIOR* web pages, then I would seriously consider doing all <form> creation using server-side code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    David801 (08-16-2014)

  • #3
    New to the CF scene
    Join Date
    Aug 2014
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    It's really tough for us to guess what will work best for you without knowing the details of the needed application.

    Personally, I would have thought that the best choice might be putting the drop-down choices into a DB and then building the page (say using PHP) by making a SQL query to the DB.

    It's not clear to me why you would use JavaScript to create the <select>s in the first place. Does <select name="two"> depend on what the user chose in <select name="one">??? Or similar?

    If the <form> contents depend on changes made within the same <form>, then yes, JS will be the way to go. But even then I might consider using AJAX and DB queries to get the <select> contents.

    If the <form> contends depend on *PRIOR* web pages, then I would seriously consider doing all <form> creation using server-side code.
    Yes, you've got the idea with the select example in your post. The options are dependent on other questions within the same form, all though more complicated. What the user chooses in questions 1 and 2 may remove certain options the user can select in questions 7, 8 and 9 but then what you select in questions 5 and 6 may add a few of those options that 1 and 2 originally removed.

    Even with my limited knowledge, I recognize that having a DB to do this would make life much easier( all though I'd not thought about doing what you suggested), but there is an issue with that. Because the website itself is being developed by a 3rd party shopping cart provider I have limited access to the DB that they are maintaining, and it costs my company money to edit this DB. I don't even know where our AJAX files are, I'm not aloud access to them because its "proprietary code" according to the shopping cart company and this is the case with a LOT of the website. I have control over the form code and the general appearance of the website, and that's about it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •