You are here:

DHTML/form javascript and MSIE

Advertisement


Question
Hi! I have a problem here, than I can't solve. The following code works fine on Mozilla-based browsers, but it shows alerts and does not work on MSIE. What could been happening? Thank you very much

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>The form that does not submit in MSIE</title>
  <script type='text/javascript'><!--
     function darle(idsol,pest){
        document.forms['form1'].action = 'otro.html' ;
        document.forms['form1'].submit();
     }
  //-->
  </script>
</head>
<body>
<form id='form1' name='form1' action='otherpage.php' method='post' enctype='multipart/form-data'>
  <select class='inpt' id='alternativa' name='alternativa'>
     <option value='0' selected='selected'>etapa</option>
     <option value='1' >alternativa</option>
  </select>
</form>
  <table>
     <tr><td style='background-color:#ffffff'>lista de tareas</td>
        <td style='background-color:#9999ff'>
              <a href='javascript:void(0)' onclick='darle(0,1)'>reconocimientos</a>
        </td>
     </tr>
     <tr><td colspan='2'>the content
        </td>
     </tr>
  </table>
</body>
</html>


Answer
Replace the javascript:void(0) with a # symbol, like this:

a href='javascript:void(0)' onclick='darle(0,1)'>reconocimientos</a>

<a href='#' onclick='darle(0,1)'>reconocimientos</a>

I believe IE6 was trying to execute the void(0) instead of the actual function you wanted to call.  Seems to work now, though.

- Andrew

DHTML

All Answers


Answers by Expert:


Ask Experts

Volunteer


Andrew Hoffman

Expertise

Ask me about JavaScript, CSS, HTML5/XHTML, or PHP. Chances are I'll be able to help you. I know the economy is in the tank, but if you like my answer, please consider donating a few bucks. It's like tipping your barista, if your barista served fresh code instead of coffee.

Experience

I started doing this when boy bands were still cool.

Education/Credentials
I read a lot of nerdy books to get here.

©2012 About.com, a part of The New York Times Company. All rights reserved.