SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    not sure where to start on list menu and hidden field

    I have a sql/recordset setup that returns an id number and description.

    For example:
    4 test
    7 test44
    9 test123

    I then have a drop down list that contains the id numbers. I'd like the recordset to return the matching record for whatever is selected in the drop down list. So if the drop down list equals "4". Then "test" would appear in the value of a hidden form field. If "9" was selected in the combo box then "test123" would be entered into the hidden form field. I'm not sure how to specify the value from the drop down list in my sql statement and also do not know how to update the value when the user changes the drop down list selection.

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Netherlands
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this:

    in the head of the document

    Code:
    function refresh_hidden(n){
    
     theText = n.options[n.options.selectedIndex].innerHTML;
     document.getElementById['theHiddenField'].value = theText;
    
    }
    Then your selectbox:
    <select id="test" onChange="refresh_hidden(this)">
    <option value="4">Test</option>
    etc...
    </select>

  3. #3
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to clarify. I'm trying to perform this example:
    N-1 Dependent Field(at the bottom of the page)
    http://iakt.rdsnet.ro/demo/widgetsDemo/
    Just wanted to make sure you understood my first post. Does your solution change at all or did you fully understand me the first time?


    Quote Originally Posted by Atrix
    try this:

    in the head of the document

    Code:
    function refresh_hidden(n){
    
     theText = n.options[n.options.selectedIndex].innerHTML;
     document.getElementById['theHiddenField'].value = theText;
    
    }
    Then your selectbox:
    <select id="test" onChange="refresh_hidden(this)">
    <option value="4">Test</option>
    etc...
    </select>

  4. #4
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by johnjohn2
    Just to clarify. I'm trying to perform this example:
    N-1 Dependent Field(at the bottom of the page)
    http://iakt.rdsnet.ro/demo/widgetsDemo/
    Just wanted to make sure you understood my first post. Does your solution change at all or did you fully understand me the first time?
    That's not quite what you asked at first, so the solution that was provided won't really help you out.

    You would use the onchange event on the select list, but you need an array to keep track of the related information.

    Code:
    <html>
    <head>
      <script>
        var vManufacturerList = new Array();
        vManufacturerList[0] = "Honda";
        vManufacturerList[1] = "Toyota";
        vManufacturerList[2] = "Ford";
        vManufacturerList[3] = "Chrysler";
        vManufacturerList[4] = "Dodge";
    
        function LoadManufacturer(pSelection)
          {
          document.MyForm.Manufacturer.value = vManufacturerList[pSelection.options.selectedIndex] ;
          }
      </script>
    </head>
    <body onload="LoadManufacturer(document.MyForm.Model)">
      <form name="MyForm">
        <label for="Model">Model: </label>
        <select name="Model" id="Model" onChange="LoadManufacturer(this);">
          <option>Pilot</option>
          <option>Prius</option>
          <option selected>Focus</option>
          <option>Town and Country</option>
          <option>Avenger</option>
        </select>
        <br>
        <label for="Manufacturer">Manufacturer: </label>
        <input type="text" id="Manufacturer" name="Manufacturer" value="">
    </body>
    </html>
    Charles

  5. #5
    SitePoint Guru johnjohn2's Avatar
    Join Date
    Apr 2004
    Location
    here
    Posts
    746
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. You suggestion looks like it's for static entries. Is it much different for the recordsets my data is dependent on?

    Quote Originally Posted by Guimauve
    That's not quite what you asked at first, so the solution that was provided won't really help you out.

    You would use the onchange event on the select list, but you need an array to keep track of the related information.

    Code:
    <html>
    <head>
      <script>
        var vManufacturerList = new Array();
        vManufacturerList[0] = "Honda";
        vManufacturerList[1] = "Toyota";
        vManufacturerList[2] = "Ford";
        vManufacturerList[3] = "Chrysler";
        vManufacturerList[4] = "Dodge";
    
        function LoadManufacturer(pSelection)
          {
          document.MyForm.Manufacturer.value = vManufacturerList[pSelection.options.selectedIndex] ;
          }
      </script>
    </head>
    <body onload="LoadManufacturer(document.MyForm.Model)">
      <form name="MyForm">
        <label for="Model">Model: </label>
        <select name="Model" id="Model" onChange="LoadManufacturer(this);">
          <option>Pilot</option>
          <option>Prius</option>
          <option selected>Focus</option>
          <option>Town and Country</option>
          <option>Avenger</option>
        </select>
        <br>
        <label for="Manufacturer">Manufacturer: </label>
        <input type="text" id="Manufacturer" name="Manufacturer" value="">
    </body>
    </html>
    Charles

  6. #6
    SitePoint Addict Guimauve's Avatar
    Join Date
    Aug 2004
    Location
    Chicago
    Posts
    255
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript doesn't have a built-in idea of recordset and bound fields, so you have to do it yourself. Your server side process can generate the Array definitions and assigments so the static list in the sample above would be dynamically generated by the server.

    If you have more than two related fields you may want to look into creating an object in JavaScript so that you can do something like;

    Code:
    vArray[0] = new MyObject("Honda","Pilot","4Door", "4WD")
    Charles


Bookmarks

Posting Permissions

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