Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submit() works fine in Firefox but does nothing in IE??? 1

Status
Not open for further replies.

faeryfyrre

Programmer
Aug 4, 2003
198
AU
Hi, I've got a javascript issue that i can't seem to overcome. I have a page that works fine in Firefox but i can't get it working in IE6. Annoying thing is no error is actually thrown, the form just does not submit.

If anyone can spot the problem, I'll love you long time.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript" type="text/javascript">
 function submitPriceSearch(fProductID,fPostCode,fZoom){
    var frm = document.getElementById("frmPriceSearch");
    
    frm["ProductID"].value = fProductID;
    frm["postCode"].value = fPostCode;
    frm["zoom"].value = fZoom;

    frm.submit();
  }
</script>
</head>

<body>
          <form name="priceSearch" id="frmPriceSearch" action="index.cfm?engine=search.price" method="post" >
            <!--- <input type="text" name="product" value="">product:<br /> --->
            <input type="text" name="postCode" value="">postCode:<br />
            <input type="text" name="zoom" value="">zoom:<br />
			<input type="text" name="ProductID" value="">product ID:<br />
            <!--- <input type="text" name="package" value="">package:<br /> --->
            <input name="Submit" type="SUBMIT" class="formButton" value="SEARCH">
          </form>
<br>
<a href="javascript:void(0);" onclick="submitPriceSearch('152','4000','0')">Go</a>
</body>
</html>

Alec Doughty
Doughty Consulting P/L

&quot;Life's a competition. Play hard, but play fair&quot;
 
Change this:

Code:
<input name="Submit" type="SUBMIT" class="formButton" value="SEARCH">

to this:

Code:
<input name="[b]mySubmit[/b]" type="SUBMIT" class="formButton" value="SEARCH">

It's most likely that the form was being confused as to whether to call the submit method, or access the submit button. You should NEVER name your form elements with the same name as a form method.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
faeryfyrre wrote:
>Hi, I've got a javascript issue that i can't seem to overcome. I have a page that works fine in Firefox but i can't get it working in IE6. Annoying thing is no error is actually thrown, the form just does not submit.

This is a good question and it is an instance where you come across from time to time statement like when there are multiple handlers are attached, the exact behaviour may be dependent of the exact implementation and unexpected result may arise. Here is the scaled down and clear illustration with comments for acceptable solutions.
Code:
<html>
<head>
<script language="javascript">
    function submitit(qstr) {
        var frm=document.getElementById("searchform");
        frm["q"].value=qstr;
	frm.submit();
    }
	
    function fillit(qstr) {
        var frm=document.getElementById("searchform");
        frm["q"].value=qstr;
        //frm.submit();
    }
</script>
</head>
<body>
    <form name="searchform" id="searchform" method="get" action="[URL unfurl="true"]http://www.google.com/search?hl=en">[/URL]
    <input type="text" name="q" />
    </form>
    <div>
    [0] <a href="javascript:document.forms['searchform'].submit();" onclick="fillit('javascript')">Go-search-0</a>
    </div>
    <div>
    All is fine, ff/nn/ie all takes it gracefully.
    </div>
    <div>
    [1] <a href="javascript:void(0);" onclick="submitit('javascript')">Go-search-1</a>
    </div>
    <div>
    onclick is executed first, in ie, href overrides the submit url call, but ff/nn let pass and never let void have a chance.
    This is another illustration of "unexpected behaviour" when multiple handling on some events. The behaviour very much dependent on concrete implementation.
    </div>
    <div>
    [2] <a href="#" onclick="submitit('javascript')">Go-search-2</a>
    </div>
    <div>
    Now, href is not blocking, hence, both ff/nn/ie works gracefully as expected. This is the simplest solution.
    </div>
</body>
</html>
Hence, the easiest solution with less disturbance to your existing script is to set the href to non blocking empty bookmark, href="#" rather than blocking "javascript:void(0)".
 
Thanks to everyone who responed.

Particular thanks go to Tsuji for the answer that worked.

Alec Doughty
Doughty Consulting P/L

&quot;Life's a competition. Play hard, but play fair&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top