Showing posts with label form submit twice. Show all posts
Showing posts with label form submit twice. Show all posts

Thursday, December 3, 2009

javascript submitting form twice

I have form with hidden fields. When i do change the country select box, taking the value of select box  & updating  the same in hidden field. When i hit the search button to search countries, i am submitting the form using javascript.

My code:

<a href="#" onclick="submitMyForm();">Search</a>

I was wondering this javascript submitted this form twice. First time with the value in the hidden box and second time with out.

We found out the problem with my javascript code. 

Correct code:

<a href="#" onclick="submitMyForm();return false;">Search</a>

So "return false;" did trick for me.

Have fun

Monday, June 15, 2009

JSP form getting submitted twice

When i was working in the struts2,hibernate and spring technology, strangely "null pointer exception" thrown for attribute which used in the form even i give valid input.

I dig this issue and found that, struts action called twice when i request for the URL. Again this also crazy for me. When debug the application, found that browser sending new request if any empty 'src' in the <img> tag present in the code.

code

<img src="">

In our case browser sent second request with empty form[no data] . so obviously "null pointer exception".

so take out or give the valid image src name and this will fix the problem.