Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax Autocompleter passing params (script.aculo.us )

Status
Not open for further replies.

gorgered

Programmer
Dec 13, 2005
24
0
0
US
Hi,

I am using script.aculo.us javascript for Autocompleter for Suggest Field.

Doc is below
It works fine, but I have an issue for which I need help. Here is what I am doing. I have a state select box, when user selects the state I pass selected state and the value that's user inputs as a paramter, so that I can get the list of city's for that state.

Problem : If the state dropdown list is pre-selected (ie., the word selected in select options) it always passed the value that has the word "selected" in options.

So the question is how do I dynamically set the value for the State as the Select is pre proulated from DB.

Blow code works fine.

Code:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Suggest Test</title>
    <script src="js/ajax/prototype.js" type="text/javascript"></script>
    <script src="js/ajax/scriptaculous.js" type="text/javascript"></script>
     <style type="text/css" media="screen">
      .selected { background-color: #888; }
     </style>
  </head>
  <body>
    <div class="auto_complete" id="match_auto_complete" style="display:none;border:1px solid black;background-color:#86A5DD;width:200px"></div>
    <form name="form0">
      <table cellspacing="3" cellpadding="2" border="1" width="100%">
        <tr>
          <td width="25%">State</td>
          <td width="75%">
            <select size="1" name="state">
              <option value="VA">VA</option>
              <option value="MD">MD</option>
            </select>
          </td>
        </tr>
        <tr>
          <td width="25%">City</td>
          <td width="75%">
            <input type="text" name="city" autocomplete="off"/>
            <script type="text/javascript" language="javascript" charset="utf-8">
                // <![CDATA[
                 new Ajax.Autocompleter('city','match_auto_complete','suggestAction.do', {parameters: "state="+ $F('state'), minChars: 2});
                // ]]>
            </script>
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>

Code that does not work (Its not passing the selected value but it passes the value that has the word selected) It is always passing MD even If I select VA

Code:
<%@ page contentType="text/html;charset=windows-1252"%>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Suggest Test</title>
    <script src="js/ajax/prototype.js" type="text/javascript"></script>
    <script src="js/ajax/scriptaculous.js" type="text/javascript"></script>
     <style type="text/css" media="screen">
      .selected { background-color: #888; }
     </style>
  </head>
  <body>
    <div class="auto_complete" id="match_auto_complete" style="display:none;border:1px solid black;background-color:#86A5DD;width:200px"></div>
    <form name="form0">
      <table cellspacing="3" cellpadding="2" border="1" width="100%">
        <tr>
          <td width="25%">State</td>
          <td width="75%">
            <select size="1" name="state">
              <option value="VA">VA</option>
              <option value="MD" selected>MD</option>
            </select>
          </td>
        </tr>
        <tr>
          <td width="25%">City</td>
          <td width="75%">
            <input type="text" name="city" autocomplete="off"/>
            <script type="text/javascript" language="javascript" charset="utf-8">
                // <![CDATA[
                 new Ajax.Autocompleter('city','match_auto_complete','suggestAction.do', {parameters: "state="+ $F('state'), minChars: 2});
                // ]]>
            </script>
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>


Help is greatly appriceated.

Thanks
Gorge
 
Hi,

Got the solution, had to change the source of the lib. I defenetly would like to know how to extend Autocompleter insted fo changing the code.



Thanks
Gorge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top