#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13

    Angry Javascript problem when submitting through NS4


    I have a form that I want to validate with javascript and then submit. The form name is vbform and here's the javascript function that gets called.

    Code:
    function replyIm() {
      if(document.vbform.message.value == '') {
        alert('Please enter a reply message.');
      }
      else {
        document.vbform.cmd.value = 'doreplyim';
        document.vbform.submit();
      }
    }
    I call the function like this:

    Code:
    <a href="javascript:replyIm(void(0));"><img src="images/im_send.gif" border="0" alt="Send Im"></a>
    The reason I do that is because I have to buttons, one to reply and one to close the im.

    This works fine in everything but NS4, where it gives a "document contains no data" message. The thing is it still submits the form and replies. The window just doesn't close like it should in the post back code.

    Here's what I call in the post back section to close the window. This is echo'd from php code:

    Code:
    echo "<html><head><title></title><script language=\"javascript\"><!--\n
    window.close(); //-->\n
    </script></head><body></body></html>";
    Thanks for any help,

    Mark
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    What's this?

    <a href="javascript&#58;replyIm(void(0));">

    You're sending an argument to a function that goes nowhere. Perhaps you meant this:

    <a href="javascript&#58;void replyIm()">

    This will void (eliminate) any return value from the function which might be loaded as a new document, which, naturally, is the default disposition of any hyperlink click. See if that helps...
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    I tried your call of the function, but I still get the "document contains no data" alert in NS4. Could it have anything to do with the way I'm calling functions for this form?

    Thanks,

    Mark
  6. #4
  7. My beer is empty....
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    South Africa
    Posts
    73
    Rep Power
    13
    Why don't you use something like this to submit the form:

    <form name="vbform" action="where_ever.php" method="get" onsubmit="return checkDetails()">

    with <input type="image" src="images/im_send.gif"> to submit the form.

    Use javascript function:

    function checkDetails() {
    if(document.vbform.message.value == '') {
    alert('Please enter a reply message.');
    return false;
    }
    else {
    document.vbform.cmd.value = 'doreplyim';
    document.vbform.submit();
    return true;
    }
    }

    to do rest.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    Try this:

    Code:
    echo "<html><head><title></title></head><body onload=\"self.close()\"></body></html>";
    You'll get a prompt - unless this is a window opened with JavaScript. It's a security feature. Hope that helps.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    Thanks, I'll give that a try when I get a chance.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    No luck I think the problem is when the form submits. It seems to think the document contains no data at that point.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    Can you post a document containing your form which replicates the above behaviour? I'm not sure I understand the order things are happening in as above...
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    Here's the form. The variables are like that because it's a template in vBulletin:

    Code:
    <form name="vbform" action="im.php" method="post">
    <input type="hidden" name="cmd">
    <input type="hidden" name="useridto" value="$useridfrom">
    <input type="hidden" name="imsessionid" value="$imsessionid">
    <input type="hidden" name="imid" value="$imid">
    <input type="hidden" name="s" value="$session[sessionhash]">
      <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" width="100%" align="center">
      <tr>
        <td>
          <table border="0" cellpadding="2" cellspacing="1" width="100%">
            <tr>
              <td bgcolor="#663333"><normalfont color="#ffffff"><b>Instant Message from $usernamefrom</b></normalfont></td>
            </tr>
            <tr>
              <td bgcolor="#f7f7f7"><normalfont>($imdate) <b>$usernamefrom</b>: $immessage
              <p align="right"><smallfont><a href="javascript:void viewFullIm();">View Full Im</a></smallfont></normalfont>
              </td>
            </tr>
            <tr>
              <td bgcolor="#dedfdf">
              <textarea class="bginput" wrap="virtual" cols="40" rows="4" name="message"></textarea>
              </td>
            </tr>
            <tr>
              <td bgcolor="#f7f7f7"><input type="checkbox" name="banuser" onClick="void banUserFromIM();">
              <normalfont> Ban user from instant messenging you.</normalfont>
              </td>
            </tr>
            <tr>
              <td bgcolor="#dedfdf">$vbcode_smilies</td>
            </tr>
            <tr>
              <td bgcolor="#f7f7f7"><a href="javascript:void replyIm();"><img src="images/im_send.gif" border="0" alt="Send Im"></a>&nbsp;
              <a href="javascript:void closeIm();"><img src="images/im_close.gif" border="0" alt="Close Im"></a>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>
    </form>
    Here's the javascript code:
    Code:
    function newIm() {
      if(document.vbform.message.value == '') {
        alert('Please enter a new message.');
      }
      else {
        document.vbform.cmd.value = 'donewim';
        document.vbform.submit();
      }
    }
    function banUserFromIM() {
      document.vbform.cmd.value = 'dobanuser';
      document.vbform.submit();
    }
    function replyIm() {
      if(document.vbform.message.value == '') {
        alert('Please enter a reply message.');
      }
      else {
        document.vbform.cmd.value = 'doreplyim';
        document.vbform.submit();
      }
    }
    function closeIm() {
      document.vbform.cmd.value = 'docloseim';
      document.vbform.submit();
    }
    function viewFullIm() {
      document.vbform.cmd.value = 'doviewfullim';
      document.vbform.submit();
    }
    Mark
    Last edited by LancerForums; April 15th, 2002 at 09:12 AM.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Dublin
    Posts
    413
    Rep Power
    14
    At what stage does the problem appear? I can't replicate it here but I'm submitting to a non-existent page so that might be why...

    Why can't you use the following?
    Code:
             <input type=image name=send src="images/im_send.gif" border="0" alt="Send Im"></input> 
             <input type=image name=close src="images/im_close.gif" border="0" alt="Close Im"></input>
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    It appears to occur when the javascript has submitted or is submitting. I don't know whether the next page is missing something that netscape thinks should be there, but the php code is:

    Code:
    echo "<html><head><title></title></head><body onload=\"self.close()\"></body></html>";
    When I submit the form in NN4, I get the alert message and the window does not close as it should. When I manually close it and refresh the page. I see the new message has been sent to me, so I know the form submits with all the info, NN4 just thinks there's something wrong and I have no clue what that is

    Mark
  22. #12
  23. My beer is empty....
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2002
    Location
    South Africa
    Posts
    73
    Rep Power
    13
    This is just a wild guess, but I would thought that you if you close a window while it still actually being opened you are going to get an error. If you use something like Delphi you get errors anyhow (Can' close window in a visible/create event).

    I didn't think of it earlier but why don't you try the following code for the page:

    echo "<html><head><title></title></head><body><script langauge=\"JavaScript\"> self.close(); </script></body></html>";

    This should let the page load first, and after it has loaded run the script telling the window to close.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Posts
    39
    Rep Power
    13
    Still no luck. The message I get is "document contains no data". I think NN4 thinks the form has no data when in fact it does.

    Thanks for the help guys. This one is just really confusing.

    Mark
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    LancerForums -

    Try this, couldn't hurt:

    "><a href="javascript&#58;;" onclick="replyIm();return false;"><

    ..for all the image submissions. When that doesn't work - I'd try to isolate the problem by submitting a simpler test form using an ordinary <input type="submit"> button. Instead of echoing back a self-closing page, stick a <body onload="alert()"> in there as a flag. If you can narrow it down to what is working - and what isn't - you'll have the clue you need to fix it. Might want to type "document has no data" into google - I found that instructive.

    Domisedon - your snippet doesn't load the page first - the script is run while the page is loading. This was remedied a few posts back.

IMN logo majestic logo threadwatch logo seochat tools logo