开发者

Onclick function not working in firefox [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
function get() {

    $.post(
        'postchatfame.php', 
        {
            comment: postchatfamemsg.comment.value,
            userid: postchatfamemsg.userid.value
        },
        function(output) {
            $('#walls').html(output).show();
        }
 开发者_C百科   );

    document.forms["postchatfamemsg"].reset();

}

This is my code I used as Ajax, to store information into DATABASE. and returned some information in tabular form to the same page without refreshing page. I called this function onclick of button by writing this code.

<input name="a" type="button" value="Share" onClick="get();"/>


Because Fx uses standards

comment: postchatfamemsg.comment.value, will not work on its own. It will work in IE for example because IE overloads the scope with all possible things, which is also why document.getElementById('formname') will work in IE and not in Fx

Use comment: document.forms["postchatfamemsg"].comment.value,

Complete code

function sedData() { // get is a poor function name, especially when you post
    var form = document.forms["postchatfamemsg"];
    $.post(
        'postchatfame.php', 
        {
            comment: form.comment.value,
            userid: form.userid.value
        },
        function(output) {
            $('#walls').html(output).show();
        }
    );

    form.reset();

}


I suggest a different name for the function - some names already have a meaning in HTML and the DOM, so using such a name may conflict with them (calling a function submit has similar problems).

Why not give it a more descriptive name - getChatFame, for example?


Ask yourself:

  • Did you define your function physically in code before trying to use it?
  • Is jQuery or whatever library you are using loaded before you try to use $.ajax?
  • Do you have errors in the JavaScript console?
  • Can you verify that any part of the process worked in the troublesome browser?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜