0
<div id = '147'> 
    <u><b><font color = 'blue'  onClick = 'javascript:showbox(147)'>Comment </font</b></u>
</div>

<script type='text/javascript'>
<!--        
    function showbox(var1) {
        document.getElementById(var1).innerHTML = var1 + " <form name = 'commentform'  method = 'post' action = ''><input type='text' name = 'comment' value='Enter Your Comment' ><input type='hidden' value= " + var1 + " name='wallpostid'> <input type ='hidden' value = '$userid' name = 'userid' > <input type='submit' name = 'send' value='Post your Comment' onClick='javascript:postcomment()'>  </form>";
        <b onclick= 'postcomment()' > </b>;
    }
    function postcomment() {
        document.commentform.comment.submit();
    }
-->
</script>

Above is the code. It is working in FF but not in IE or Chrome.

Can anyone tell where I went wrong. Any solution to make it work in all browsers?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Ahsan
  • 11
  • 1
  • 3
    What exactly is not working? What does it do and what do you expect it to do? Btw. I highly doubt it "works" in Firefox, you have JS syntax errors. And you really should have a look at CSS. – Felix Kling Aug 21 '11 at 12:37

5 Answers5

1

There are some typos here is one:

"...<input type='hidden' value= " + var1 + " name='wallpostid'>... "

"...<input type='hidden' value='" + var1 + "' name='wallpostid'/>... "

Note the / and the two '

Also this line

    <b onclick= 'postcomment()' > </b>;

does not do anything as it is in javascript and not html section of the file.

Hogan
  • 69,564
  • 10
  • 76
  • 117
1

First of all, your markup is a bit of a mess so no wonder there's a mess up amongst it. However I think your problem is that $userid is being passed through as a string and not it's value as a variable of some sorts.

Here's your markup tidied up a bit (but still leaves much to be desired) with some redundant stuff removed and the $userid echoed PHP-style.

<div id="147" onclick="showbox(this)"><a href="#">Comment</a></div>
<script>
function showbox(el) {
    el.innerHTML = el.id + '\
        <form name"="commentform" method="post" action="">\
            <input type="text" name="comment" value="Enter Your Comment" />\
            <input type="hidden" value="' + el.id + '" name="wallpostid" />\
            <input type="hidden" value="<?php echo $userid; ?>" name="userid" />\
            <input type="submit" name="send" value="Post your comment">\
        </form>';
}
</script>
Marcel
  • 27,922
  • 9
  • 70
  • 85
0
document.getElementById(var1).innerHTML = var1 + " <form name = 'commentform'  method = 'post' action = ''><input type='text' name = 'comment' value='Enter Your Comment' /><input type='hidden' value= '" + var1 + "' name='wallpostid' /> <input type ='hidden' value = '$userid' name = 'userid' /> <input type='submit' name = 'send' value='Post your Comment' onClick='javascript:postcomment()' /></form><b onclick= 'postcomment()' ></b>";
Brett Walker
  • 3,566
  • 1
  • 18
  • 36
0

A bunch of things are wrong:
1. ID's can't start with a numeral
2. Use onclick, not onClick
3. Don't put javascript: in your onclick
4. Your <b onclick... is useless
5. Your postcomment function just submits the form - you don't need JS for that
6. Make sure you set an action for the form
Here's the complete fixed code:

<div id='div147'><u><b><font color='blue' onclick='showbox(147)'>Comment</font></b></u></div>
<script type='text/javascript'>      
function showbox(var1) {
    document.getElementById(var1).innerHTML = var1 + " <form name='commentform'  method='post' action='someurl.php'><input type='text' name='comment' value='Enter Your Comment'><input type='hidden' value='" + var1 + "' name='wallpostid'><input type='hidden' value='$userid' name='userid'> <input type='submit' name='send' value='Post your Comment'>  </form>';
}
</script>
Abraham
  • 20,316
  • 7
  • 33
  • 39
0

While adding inner html some times run time errors are shown by some browsers. Reffer this question for better understandability for how to add inner html. Also I dont think you need onclick function for submitting form. It will submit automatically after clicking on submit

Community
  • 1
  • 1
Sarin Jacob Sunny
  • 2,138
  • 3
  • 29
  • 61