Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript form submit does not work in chrome

I have the following html:

<body>
<form action="site1">
    <input type="image" name="submit" border="0" src="images/front/search_travel.png" alt=""  onclick="provider_popup();"/>
</form>

<form  name="frmRight1"  action="site2" target="_blank" >
    <input type="hidden" name="sector_id" id="sector_id" value="90" />
    <input type="submit" style="visibility:hidden;" />
 </form>

 <script type="text/javascript">
 function provider_popup (){
        document.frmRight1.submit();
        return false;
  } 
</script>
</body>

And while I submit the button with name submit, I get one another tab and it will load 'site2'

But this process is not working in chrome.

Let me know the reason

like image 220
Linto Avatar asked Jul 19 '11 21:07

Linto


1 Answers

Okay, you also needed to prevent the image button from submitting its form. Your function returned false, but you need to return that to the onclick, hence the problem. Do it like this:

onclick="return provider_popup();"

I recommend you ditch the <input type="image"> approach anyway, and use a pure element with an onclick attribute. Makes your HTML much simpler i.e.

<body>
    <img src="images/front/search_travel.png" alt="Submit" onclick="provider_popup();" />

    <form  name="frmRight1"  action="site2" target="_blank" >
        <input type="hidden" name="sector_id" id="sector_id" value="90" />
        <input type="submit" style="visibility:hidden;" />
    </form>

     <script type="text/javascript">
     function provider_popup () {
            document.forms['frmRight1'].submit();
      } 
    </script>
</body>

Another alternative is to wrap the image in an anchor <a href... and apply the onclick to that.

like image 110
James McCormack Avatar answered Sep 22 '22 21:09

James McCormack