0

I've two forms in different divs. One is search form and another is login form.

Here is my problem: When I click search bar, type something and hit enter, form submits.

But when I enter my login information and press enter, nothing happens.

Here is the HTML code:

<div id="xxxx">
    <form action="xxxxx.php" method="get" name="xxxxx">
        <table>
            <tr>
                <td><input type="text" size="xxx" maxlength="xxxx" name="xxxx" id="xxxx"></td>
                <td><input type="button" value="Ara"></td>
            </tr>
        </table>
    </form>
</div>
<div id="xxxxxxx"><form name="xx" action="xxxxxx.php" method="post">
    <table>
        <tr>
            <td>Kullanıcı Adı:</td>
            <td><input type="text" name="xxxx" id="xxx" maxlength="xx" size="xx"></td>
            <td>Şifre:</td>
            <td><input type="password" name="xxxx" id="xxx" maxlength="xx" size="xx"></td>
            <td><input type="button" name="xxxx" id="xxx" value="Oturum Aç"></td>
        </tr>           
    </table>
</form></div>

Don't mind the xxx's

EDIT:

I'm calling a simple JS function to submit so I can't use input type submit.

Here is JS

 function tik()
{
//after a few controls
    document.forms["formName"].submit();
}

Of course formname changes for different forms

Diga
  • 481
  • 2
  • 9
  • 20

3 Answers3

1

I think it should work with <input type="submit"/>, initialize onsubmit attribute to call tik()

<div id="xxxx">
  <form action="xxxxx.php" method="get" name="xxxxx" onsubmit="tik()">
    <table>
      <tr>
        <td>
          <input type="text" size="xxx" maxlength="xxxx" name="xxxx" id="xxxx">
        </td>
        <td>
          <input type="submit" value="Ara">
        </td>
      </tr>
    </table>
  </form>
</div>
<div id="xxxxxxx">
  <form name="xx" action="xxxxxx.php" method="post" onsubmit="tik()">
    <table>
      <tr>
        <td>Kullanıcı Adı:</td>
        <td><input type="text" name="xxxx" id="xxx" maxlength="xx" size="xx"></td>
        <td>Şifre:</td>
        <td><input type="password" name="xxxx" id="xxx" maxlength="xx" size="xx"></td>
        <td><input type="submit" name="xxxx" id="xxx" value="Oturum Aç"></td>
      </tr>           
    </table>
  </form>
</div>
A human being
  • 1,220
  • 8
  • 18
1

You have to simply change your <input type="button" ../> to <input type="submit" .../> and everything should works

Michał Kutra
  • 1,202
  • 8
  • 21
  • Look at this one: http://jsfiddle.net/4ngc2xry/ (doesn't work), and at this one: http://jsfiddle.net/4ngc2xry/1/ (it does) – Michał Kutra Jan 14 '15 at 21:13
  • can I use submit with JS? – Diga Jan 14 '15 at 21:14
  • Yes, You can. IMHO You should put type="submit" to each form element, and in JS You can still use submit event to manage bahevior of your form. – Michał Kutra Jan 14 '15 at 21:16
  • Can you tell me how to stop submitting? With button, I check for errors. if(error) alert else(submit) but with submit type, when I use this code, it alerts and submits anyway. So I need to stop submit proccess with JS. – Diga Jan 14 '15 at 21:17
  • Simply $('form').on('submit', function(){return false}) will stop submitting form – Michał Kutra Jan 14 '15 at 21:18
  • can't I do this without jQuery? it's not allowed in this project. – Diga Jan 14 '15 at 21:20
  • 1
    I've found this link and it helped: http://stackoverflow.com/questions/3350247/how-to-prevent-form-from-being-submitted – Diga Jan 14 '15 at 21:24
0

edit Make sure to utilize <input type="submit">

Also:

Make sure the ID of your two buttons are different. Looks like in the first button you don't have an ID set.

make sure the "xxx.php" actions on the forms are not mixed up.

and lastly, make sure your form names are different (looks like they are given the amount of x's in each name value).

Sanova
  • 551
  • 3
  • 10