0

All the button in the form, submit the form automatically, but I need other button function.

Code here:

     <html lang="en">
     <title>NTF Catering Service</title>
     <meta charset="utf-8">
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">              </script> 
       <script src="js/js.1.js" type="text/javascript"></script>
    </head>
   <body>
       <form action="create.php" method="post">

         <select multiple="multiple" class="options" id="textarea">
         <option value="item1">Item 1</option>
         <option value="item2">Item 2</option>
         <option value="item3">Item 3</option>
         <option value="item4">Item 4</option>
          <option value="item5">Item 5</option>
        </select>


    <button id="copy">Copy</button>
    <button id="remove">Remove</button>

     <select id="textarea2" multiple class="remove">


<input type="submit" name="submit" />
</form>
    </select>
     </html>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user3211646
  • 17
  • 1
  • 6

5 Answers5

2

If you mean that all the Buttons submit your form then add the following to the elements: type="button"

<button type="button" id="copy">Copy</button>
<button type="button" id="remove">Remove</button>

This should ensure only the will submit the form

Then control these via your jquery code:

    $('#copy').on('click', function(e){ ///do stuff here });
    $('#remove').on('click', function(e){ ///do stuff here });

or add onclick to the buttons:

<button onclick="someCopyfunction();" type="button" id="copy">Copy</button>
<button onclick="someRemovefunction();"  type="button" id="remove">Remove</button>

etc

Simon Davies
  • 3,668
  • 9
  • 41
  • 69
  • tnx for your reply, but i need other buttons function because and is other function a jquery of 1textbox submited to another textbox. but i need also the for the textarea to submit to database – user3211646 Jan 22 '14 at 11:26
  • then in jquery you control them as in $('#copy').on('click',function(e){}) etc – Simon Davies Jan 22 '14 at 11:28
1

Since you tagged jQuery and Javascript you can also use:

$('input[name="submit"]').click(function(event){
  event.preventDefault();
  //Do other stuff here
});
Leon Hooijer
  • 584
  • 3
  • 16
1

By default <button> tags are submit button , to make them just button use

<button type="button">copy</button>
<button type="button">Remove</button>

Check this what's the standard behavior when < button > tag click? will it submit the form?

Note Always specify the type attribute for a <button> element. Different browsers use different default types for the element.

Use <input> to create buttons in an HTML form.

Community
  • 1
  • 1
niko
  • 9,285
  • 27
  • 84
  • 131
  • Ya I accept some one pointed out the mistakes in your code I just wanted to help to understand more about how and when buttons are used and how do they function. – niko Jan 22 '14 at 11:40
0

Now you are write input button inside <select> tag.

 <select id="textarea2" multiple class="remove">    

   <input type="submit" name="submit" />
   </form>
    </select>

To

</select>
 <input type="submit" name="submit" />
 </form>

Also If you don't want to submit your button

Change

<input type="submit" name="submit" />

TO

<input type="button" name="submit" onclick='yourFunction()' />
Lal krishnan S L
  • 1,684
  • 1
  • 16
  • 32
-1

Try these one if it may work for you

<form action="">
  <textarea value="text here..." type="submit" method="post"></textarea>
</form>
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
ovokay
  • 1