admin管理员组

文章数量:1410724

I need to build a form takes the user inputs and builds a query string, and then loads that URL

For example

<form id="form1" name="form1" method="post" action="">
  <p>
    <label>INPUT1
      <input type="text" name="INPUT1" id="INPUT1" />
    </label>
  </p>
  <p>
    <label>INPUT2
      <input type="text" name="INPUT2" id="INPUT2" />
    </label>    
  </p>
  <p>
    <label>
      <input type="submit" name="loadURL" id="loadURL" value="Submit" />
    </label>
    <br />
  </p>
</form>

;model=<INPUT1>&cathegory=<INPUT2>

Is there a way to do this using just HTML, or does this need javascript? Any pointers on the easiest way to do this is appreciated.

I need to build a form takes the user inputs and builds a query string, and then loads that URL

For example

<form id="form1" name="form1" method="post" action="">
  <p>
    <label>INPUT1
      <input type="text" name="INPUT1" id="INPUT1" />
    </label>
  </p>
  <p>
    <label>INPUT2
      <input type="text" name="INPUT2" id="INPUT2" />
    </label>    
  </p>
  <p>
    <label>
      <input type="submit" name="loadURL" id="loadURL" value="Submit" />
    </label>
    <br />
  </p>
</form>

http://website.&model=<INPUT1>&cathegory=<INPUT2>

Is there a way to do this using just HTML, or does this need javascript? Any pointers on the easiest way to do this is appreciated.

Share asked Dec 6, 2011 at 21:38 user547794user547794 14.5k38 gold badges108 silver badges153 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

Just set the action="/some/form/processor" and the method="get" (instead of post) and the fields in the form will be sent as the query string.

To get your example of http://website.&model=<INPUT1>&cathegory=<INPUT2> you would have

<form id="form1" name="form1" method="get" action="http://website.">
<!-- or, more simply, since the website _is_ website. -->
<form id="form1" name="form1" method="get" action="/">

The input names are used as the parameters, so your plete form would be

<form id="form1" name="form1" method="get" action="/">
  <p>
    <label>INPUT1
      <input type="text" name="model" id="INPUT1" />
    </label>
  </p>
  <p>
    <label>INPUT2
      <input type="text" name="cathegory" id="INPUT2" />
    </label>    
  </p>
  <p>
    <label>
      <input type="submit" name="loadURL" id="loadURL" value="Submit" />
    </label>
    <br />
  </p>
</form>

本文标签: javascripttake HTML inputs and build a query stringStack Overflow