0

How can I stop to redirect other tab when refreshing the browser?

<div class="tab1">User Details
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</table>
</div>
<div class="tab2">Add User
<form action="" method="post">
<p><label for="name">Name</label><input type="text" name="username"></p>
<p><label for="email">Email</label><input type="email" name="email"></p>
<input type="submit" name="submit" value="add"/>
</form>

</div>

When I click on the submit button, Form is submitting but redirecting to the first tab.

Please suggest appropriate JavaScript or jQuery code.

Jamal
  • 763
  • 7
  • 22
  • 32
Raju Reddy
  • 108
  • 3
  • 15

2 Answers2

0

Without a server side script this would not be realizable. Another way would be to not refresh the page while submitting the form:

Community
  • 1
  • 1
Marvin Emil Brach
  • 3,984
  • 1
  • 32
  • 62
0

I'm not sure which exact JavaScript you use to make the second tab visible in the first place (because you're not saying what library you use), but if you're reloading the page anyway, you can use a flag in the URL to indicate that you want to end up on tab 2.

<form action="#tab2" method="post">

(and you should also have an id="tab2" in the right place to prevent confusion for some browsers)
Then in the onload function of the page, check if the href contains '#tab2' and if so, make tab 2 visible.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
  • href for the tab2 i used #tab2. I hope you understand my java script code with this. and i hope that action="?tab=2" will not work. – Raju Reddy Jun 24 '13 at 11:05
  • Sorry about that; I wasn't thinking. I'll edit. By the way, if you really want `#tab2` to work properly under all conditions, you should change your divs to include `id="tab1"` and `id="tab2"`, respectively. – Mr Lister Jun 24 '13 at 11:33
  • Yes that tabbing functionality is working great..but when you refresh or submitting it is redirecting to 1st tab only. i am looking here for some java script code according to this without redirecting..if you are related to this please help me.. – Raju Reddy Jun 24 '13 at 12:29