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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why does my simple javascript trigger form submit action in NN7.1?

Status
Not open for further replies.

Corvette90

Programmer
Nov 5, 2002
3
0
0
US
OK, i have a very simple javascript function that works fine in IE but triggers form.submit in NN7.1
Can anyone explain why?
Code:
<html>
<head>
<title> New Document </title>
</head>
<script language=&quot;JavaScript&quot;>
<!--
function addField(){
  for(var i=0; i < document.getElementById(&quot;fields&quot;).length; i++){
    if(document.getElementById(&quot;fields&quot;)[i].selected)
      document.getElementById(&quot;display_fields&quot;).options.add(new Option(document.getElementById(&quot;fields&quot;)[i].text, document.getElementById(&quot;fields&quot;)[i].value));
  }
}
function removeField(){
  for(var i=(document.getElementById(&quot;display_fields&quot;).length-1); i >= 0; i--){
    if(document.getElementById(&quot;display_fields&quot;)[i].selected)
      document.getElementById(&quot;display_fields&quot;).options[i] = null;
  }
}
//-->
</script>

<body>
  <form action=&quot;registrant_list.jsp&quot; id=&quot;create_report_form&quot; method=&quot;post&quot;>
    <table>
      <tr>
        <td>
          <select id=&quot;fields&quot; multiple=&quot;true&quot; size=&quot;16&quot;>
            <option value=&quot;address.address1&quot;>Address1</option>
            <option value=&quot;address.address2&quot;>Address2</option>
            <option value=&quot;address.address3&quot;>Address3</option>
            <option value=&quot;address.city&quot;>City</option>
            <option value=&quot;address.state&quot;>State</option>
            <option value=&quot;address.zip&quot;>Zip Code</option>
            <option value=&quot;address.province&quot;>Province</option>
            <option value=&quot;address.country&quot;>Country</option>
            <option value=&quot;address.phone&quot;>Phone</option>
            <option value=&quot;address.fax&quot;>Fax</option>
            <option value=&quot;session.time_part&quot;>Session Time</option>
            <option value=&quot;reg_type.display_name&quot;>Registraion Type</option>
            <option value=&quot;cust_order.paid_in_full&quot;>Paid in Full</option>
            <option value=&quot;&quot;>Extra Computer Connections</option>
            <option value=&quot;&quot;>Extra Phone Connections</option>
            <option value=&quot;&quot;>Order Date</option>
          </select>
        </td>
        <td align=&quot;center&quot;>
          <button onclick=&quot;addField()&quot;>  >>  </button>
          <br/>
          <br/>
          <br/>
          <button onclick=&quot;removeField()&quot;>  <<  </button>
        </td>
        <td>
          <select id=&quot;display_fields&quot; multiple=&quot;true&quot; size=&quot;16&quot; style=&quot;width:200px&quot;>
          </select>
        </td>
      </tr>
      <tr>
        <td></td>
        <td></td>
        <td align=&quot;right&quot;><input type=&quot;submit&quot;></td>
      </tr>
    </table>
  </form>

</body>
</html>
 
hi there

i no it's a daft question have you turned off the submit action for the buttons try adding this:

<html>
<head>
<title> New Document </title>
</head>
<script language=&quot;JavaScript&quot;>
<!--
function addField(){
for(var i=0; i < document.getElementById(&quot;fields&quot;).length; i++){
if(document.getElementById(&quot;fields&quot;).selected)
document.getElementById(&quot;display_fields&quot;).options.add(new Option(document.getElementById(&quot;fields&quot;).text, document.getElementById(&quot;fields&quot;).value));
}
}
function removeField(){
for(var i=(document.getElementById(&quot;display_fields&quot;).length-1); i >= 0; i--){
if(document.getElementById(&quot;display_fields&quot;).selected)
document.getElementById(&quot;display_fields&quot;).options = null;
}
}
//-->
</script>

<body>
<form action=&quot;registrant_list.jsp&quot; id=&quot;create_report_form&quot; method=&quot;post&quot;>
<table>
<tr>
<td>
<select id=&quot;fields&quot; multiple=&quot;true&quot; size=&quot;16&quot;>
<option value=&quot;address.address1&quot;>Address1</option>
<option value=&quot;address.address2&quot;>Address2</option>
<option value=&quot;address.address3&quot;>Address3</option>
<option value=&quot;address.city&quot;>City</option>
<option value=&quot;address.state&quot;>State</option>
<option value=&quot;address.zip&quot;>Zip Code</option>
<option value=&quot;address.province&quot;>Province</option>
<option value=&quot;address.country&quot;>Country</option>
<option value=&quot;address.phone&quot;>Phone</option>
<option value=&quot;address.fax&quot;>Fax</option>
<option value=&quot;session.time_part&quot;>Session Time</option>
<option value=&quot;reg_type.display_name&quot;>Registraion Type</option>
<option value=&quot;cust_order.paid_in_full&quot;>Paid in Full</option>
<option value=&quot;&quot;>Extra Computer Connections</option>
<option value=&quot;&quot;>Extra Phone Connections</option>
<option value=&quot;&quot;>Order Date</option>
</select>
</td>
<td align=&quot;center&quot;>
<button onclick=&quot;addField()&quot; value=&quot;button&quot;> >> </button>
<br/>
<br/>
<br/>
<button onclick=&quot;removeField()&quot; value=&quot;button&quot;> << </button>
</td>
<td>
<select id=&quot;display_fields&quot; multiple=&quot;true&quot; size=&quot;16&quot; style=&quot;width:200px&quot;>
</select>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td align=&quot;right&quot;><input type=&quot;Submit&quot; value=&quot;submit&quot; name=&quot;submit&quot;></td>
</tr>
</table>
</form>

</body>
</html>

you buttons as they where in the original code that you had put where submit buttons so of course they submitted the form when you clicked them. by adding the extra values to the buttons it tells the browser and the server they are dead buttons.

so try out and let me know and i'll try again.

also NN7? latest netscape i presume.

cheersdean



 
yes, you are probably better off making those BUTTONs INPUTs:
<input type=&quot;button&quot; onclick=&quot;addField();&quot; value=&quot;add field&quot;>

:)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top