javascript - Onclick event not working in IE - Stack Overflow

I am making a PHP webpage for database search using JavaScript (search suggest). I used div to show the

I am making a PHP webpage for database search using JavaScript (search suggest). I used div to show the search suggest items.When the user clicks on this a details page for that item opens. It seems to work fine in Firefox bt it doesnot work on IE.

HTML part:

<form method="post" name="searchform" id="searchform">    
  <table class="nostyle" width="80%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="30%">Customer  &nbsp;&nbsp;&nbsp;
    <input type="text" name="search_customer" id="customer_name" class="input-text" onKeyUp="searchsuggest();"  autoplete="off"/>
    <br /><div id="search_suggest" onclick="document.getElementById('searchform').submit();"> </div></td>
    </tr>
    </table>
</form>

Please help me, I'm a newbie!

I am making a PHP webpage for database search using JavaScript (search suggest). I used div to show the search suggest items.When the user clicks on this a details page for that item opens. It seems to work fine in Firefox bt it doesnot work on IE.

HTML part:

<form method="post" name="searchform" id="searchform">    
  <table class="nostyle" width="80%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="30%">Customer  &nbsp;&nbsp;&nbsp;
    <input type="text" name="search_customer" id="customer_name" class="input-text" onKeyUp="searchsuggest();"  autoplete="off"/>
    <br /><div id="search_suggest" onclick="document.getElementById('searchform').submit();"> </div></td>
    </tr>
    </table>
</form>

Please help me, I'm a newbie!

Share Improve this question edited Oct 22, 2013 at 19:57 stash_man asked Oct 22, 2013 at 19:27 stash_manstash_man 3191 gold badge8 silver badges15 bronze badges 5
  • Do you have any errors in the IE Javascript console? – Justin Wood Commented Oct 22, 2013 at 19:29
  • Do you have any contents in your <div>? It may be so small that you aren't actually clicking on it. Are you able to log any messages to the console that would indicate your event is firing? – Crackertastic Commented Oct 22, 2013 at 19:31
  • it works fine in firefox and chrome.... Not working on IE7! – stash_man Commented Oct 22, 2013 at 19:34
  • @JustinWood I'm using IE7 – stash_man Commented Oct 22, 2013 at 19:37
  • you can get IE7 developer tools: microsoft./en-us/download/details.aspx?id=18359 – scrappedcola Commented Oct 22, 2013 at 20:15
Add a ment  | 

3 Answers 3

Reset to default 2

You don't need an ONCLICK event. type=submit already does this for you, but the element needs to be an input, not a div.

Take a look at http://jsfiddle/LM4Sg/1/ you can click on the click here in ie and it works. If you look at http://jsfiddle/LM4Sg/ you can click around the screen and never hit the EMPTY div.

You need to put something in it to click.

<div id="search_suggest" type="submit" onclick="document.getElementById('searchform').submit();">Click Here</div>

If you just want to leave the space between the div tags use an & nbsp; instead, this also makes it so you can click in ie. See the fiddle - http://jsfiddle/LM4Sg/4/

<div id="search_suggest" onclick="alert('searchform');">&nbsp;</div>

(changed to use an alert to simplify things.)

It works now... I changed my javascript

var search_suggest = document.getElementById(customer_name);
search_suggest.onclick = function(){ document.getElementById('searchform').submit();

Tried doing it with jQuery bt still did not work and don't know why IE did not work with my previous code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315514a4622200.html

相关推荐

  • javascript - Onclick event not working in IE - Stack Overflow

    I am making a PHP webpage for database search using JavaScript (search suggest). I used div to show the

    13小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信