0

Ive got a html form with a few select lists and a text box in it. I also have a submit button which is outside of the form. The reason for this is I want to construct the parameters myself, as I dont want the content of all of the select lists. The problem I am having is, that when I press my submit button,The form automaticly trys to redirect to the same page, but with a ? at the end with all the contents of the form. I am also having problems where window.location.href is not working inside the submit() javascript method, but I am not sure if this is caused by the form issue or not. Example code:

   <form>
      <input name="cName" type="text" class="input-xlarge" id="input01" placeholder=
  "Enter title" />
  <div class="control-group">
    <hr />
    <label class="control-label" for="select01">Select box 1</label>

    <div class="controls">
      <select id="select01" name="type" onChange="reportModification(this.value)">
  <option>One</option>
 </select>
 </div>
</div>
  </form>
 <button class="btn btn-primary" onClick="next()">Next</button>

This is not the exact code from the page, just a replica.So it might not be valid html in some places. Thanks for the help :)

2 Answers 2

2

The reason you get parameters in the url is that a get request is used instead of a post request. you should use:

<form method="POST" action="">

Also why is your button outside the form? you could have this instead:

   </div>
   <input class="btn btn-primary" type="submit" value="Next" onClick="next()" />
</form>
2
  • Its outside as an attempt to stop it from doing what its doing right now. Thanks for the help, ill have a go and get back to you EDIT:Works great thanks, still having the issue with window.location.href :( Jan 2, 2013 at 4:04
  • your issue with window.location.href is a javascript problem. you can create a separate question showing your js code and describing what you try to achieve, and see how the community can help you out!
    – ppetrid
    Jan 2, 2013 at 4:57
0

I think your button has to be inside the form element. You could use an onsubmit in the form element to intercept the form before it gets sent to the server. Here you could manipulate the values before they go. You would also need an action attribute in the form. If your function returns true, the data will be submitted, false and it won't.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.