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 6 of 6
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    need code to change a dropdown menu with a click of a button

    basically i have a form with lots of fields.. drop down boxes and textarea's and standard input text..
    now what i need is a way to change all of these fields with a fetch button.
    i can get the value for the fields from the perl script on my server side.

    the form basicslly sends lots of fields to my perl script and saves each field of data into seperate text docs. now my customer would like to retrieve the data back to the form to change aspects of it to be resubmitted .
    i am struggling with the simplist of codes to set the value of the fields from a javascript variable
    any ideas please.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Assuming the data saved is text in an external .txt file
    you should be able to use AJAX code to load the information to a variable.

    Provide a sample of the display you desire (the HTML portion)
    and what the data to save and restore will look like.

  • #3
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    the problem is not getting the data into the variable .
    the problem i am having is setting the fields in the form to the variable data.
    there must be a simple javascript to change a dropdown box value from a button.
    if someone could give me the code to do that then i could play with it to do what i need

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Since you don't want to provide a sample of your design,
    you'll get my SWAG as to the requirements.
    Code:
    <html>
    <head>
    <title> Untitled </title>
    <script type="text/javascript">
    
    var AJAXsimulation = [  // data from text file
      ['','','memberNo',''],                   // clear
      ['John','Smith','memberYes','Support'],  // record #1
      ['Mary','Smith','memberNo','Sales']      // record #2
    ];
    
    function FillForm(act) {
      document.getElementById('fName').value = AJAXsimulation[act][0];
      document.getElementById('lName').value = AJAXsimulation[act][1];
      document.getElementById(AJAXsimulation[act][2]).checked = true;
      document.getElementById('dept').value = AJAXsimulation[act][3];
    }
    </script>
    </head>
    <body>
    <h2>Form Fields</h2>
    <button onclick="FillForm(0)">Fill Clear</button>
    <button onclick="FillForm(1)">Member #1</button>
    <button onclick="FillForm(2)">Member #2</button>
    <p>
    <form name="myForm">
    <input type="text" value="" id="fName"> First Name<br>
    <input type="text" value="" id="lName"> Last Name<br>
    Member: <input type="radio" name="member" id="memberYes" value="yes"> Yes
    <input type="radio" name="member" id="memberNo" value="no"> No <br>
    <select id="dept">
     <option value="">Select Department</option>
     <option value="Development"> R&amp;D </option>
     <option value="Marketing"> Marketing </option>
     <option value="Sales"> Sales </option>
     <option value="Support"> Support </option>
    </select>
    </body>
    </html>
    Member buttons are just for show. Change to your own requirements (?).

  • #5
    New Coder
    Join Date
    Nov 2011
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thank you jmrker this is exactly what i wanted..

    i can play with this now

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,077
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Thumbs up

    Quote Originally Posted by gerble1000 View Post
    thank you jmrker this is exactly what i wanted..

    i can play with this now
    You're most welcome.
    Happy to help.
    Good Luck!


  •  

    Posting Permissions

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