Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lorthirk

macrumors member
Original poster
May 16, 2007
32
0
Hi all. I have, from an online RPG application (very old and not maintened indeed -- so be warned, there are a lot of code "donts" inside here) which uses the file I'm posting to submit a text; what I want is the text field called "Messaggio" to be cleared after the form is processed. The very strange thing is the error which is given in the Safari Console: at the second line of the last <script> (document.input.Messaggio.value=''), I get a "Type error: undefined value". Am I doing something notably wrong, apart the uglyness of the code I inherited?

Thanks for any help.

Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
BODY {font-size:10px; text-decoration: none; font-family:verdana; font-weight:normal;}
TD {font-size:10px; text-decoration: none; font-family:verdana; font-weight:normal;}
TABLE {font-size:10px; text-decoration: none; font-family:verdana; font-weight:normal;}
input, textarea, select {
   color:bba67a;
    background-color: #000000;
	font-family:Verdana;
	font-size:10px;
    border-right: 1px solid #bba67a;
    border-bottom: 1px solid #bba67a;
    border-left:1px solid #bba67a;
    border-top:1px solid #bba67a;

	}
</style>
<link href="temi/default/mainchat.css" rel="stylesheet" type="text/css"></head>

<SCRIPT TYPE="text/javascript">
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'height=400,width=280,scrollbars=yes');
return false;
}
</SCRIPT>


<body topmargin=0 leftmargin=0 bgcolor=#000000>

  <table cellpadding=0 cellspacing=0 border=0 align=center width="500">
    <tr>
      <td align=center colspan=6>
<!--
        <table align="center" valign="top" width="70%">
          <tr>
            <td align="center" valign="top">
-->
              <img src="divisoria.gif">
              <img src="divisoria.gif">
              <img src="divisoria.gif">
<!--
            </td>
          </tr>
        </table>
-->
      </td>
    </tr>
  <tr>
    <td align=center>Locazione
    </td>
    <td align=left>Testo
    </td>
    <td>
    </td>
    <td>
    </td>
    <td>
    </td>
    <td>
    </td>
  </tr>
  <tr>
    <form name=invio action="input.php" method=POST>
      <td valign=middle cellspacing=1>
        <input type=Text Name=Locazione class=txtbox size=15 style="font-weight:normal;font-family:Verdana;font-size:8pt" maxlength="2000" value="area">
      </td>
      <td valign=middle>
        <input type=Text Name=Messaggio class=txtbox size=60 style="font-weight:normal;font-family:Verdana;font-size:8pt" maxlength="2000" value="">
      </td>
      <td valign=middle>
        <input type="submit" value="Invia" title="Invia" class="submit">
      </td>
    </form>
    <form name=invio action="input.php?mod=sus" method=POST>
      <td valign=middle align=left>
          <input type="submit" value="Sussurra.." title="Sussurri" class="submit">
      </td>
    </form>
    <form name=invio action="input.php?mod=dadi" method=POST>
      <td valign=middle align=left>
          <input type="submit" value="Oracolo" title="Tira dadi" class="submit">
      </td>
    </form>
<!-- </form> -->

<SCRIPT TYPE="Text/Javascript">
document.invio.Messaggio.value=''
document.invio.Messaggio.focus()
</SCRIPT>
</tr>
</table>
</body>
</html>
 
god.. i know what you mean about a lot of code don't's but we wont get into that!! lol..

i'm not sure what you mean by "cleared after the form is processed"

do you mean:

1) the field be cleared when the user hits submit? (doesn't make much sense)

if you want it to be cleared when the page is processed - ie submitted.. you'll need to extract that code into a function which gets called onSubmit of the <form>


or

2) clear the field when the form loads so the field is blank ready for the user to type into

change your <body> to add the onload event so.. <body onload="docOnLoad();">

then in the <head> section where you already have <script> add the
function docOnLoad() {
document.input.Messaggio.value='';
}

that will clear the form value when the page has loaded up..

hope this helps
 
Indeed i meant your #2. The problem is: when I click on the submit button, i just want the Messaggio text field clears up, but not the other one: so a reload is not an option. Moreover, the text inputted in these two fields are sento to another frame :)(), so the frame with this code never reloads itself.
 
The problem I believe is you have two forms with the name invio. Name attributes need to be unique. Safari must be forgetting the first form and only seeing the second one when that code runs. Should be a simple fix.
 
Giving an ID to the first form, and referencing with a getElementById removes the error, but still no avail in cleaning up the text field after the submit.
 
Giving an ID to the first form, and referencing with a getElementById removes the error, but still no avail in cleaning up the text field after the submit.

Try the code below. Bold parts are what's added. With it I don't think you'll need to the code that's giving you the errors.

Code:
<form name="invio" action="input.php" method="POST" [B]onsubmit="document.getElementById('Messaggio').value='';"[/B]>
...
<input type=Text [B]id="Messaggio"[/B] Name=Messaggio class=txtbox size=60
  style="font-weight:normal;font-family:Verdana;font-size:8pt"
  maxlength="2000" value="">
...
 
Try the code below. Bold parts are what's added. With it I don't think you'll need to the code that's giving you the errors.

Code:
<form name="invio" action="input.php" method="POST" [B]onsubmit="document.getElementById('Messaggio').value='';"[/B]>
...
<input type=Text [B]id="Messaggio"[/B] Name=Messaggio class=txtbox size=60
  style="font-weight:normal;font-family:Verdana;font-size:8pt"
  maxlength="2000" value="">
...

This was a GIANT leap forward... but still not enough. Now the textfield clears up as expected, but the typed text isn't passed to the other frame, so no new text is shown in the chat... Maybe because the onSubmit is called BEFORE the form does its action?
 
This was a GIANT leap forward... but still not enough. Now the textfield clears up as expected, but the typed text isn't passed to the other frame, so no new text is shown in the chat... Maybe because the onSubmit is called BEFORE the form does its action?

Yeah, that's right. I'm a little unclear on the flow. Usually when doing a submit, you go to a different page, but sounds like you're staying on the same page. Do you have this up somewhere you can provide a link to? Also, another thing to try, take the code inside the onsubmit and put in where you were having errors, or is that what you tried before?

Edit: Something to try, though I don't have a way to test it myself. With my proposed code before, on the onsubmit, preface the code in quotes with this.submit(); This may end up ignoring the second code snippet that empties the text field, but worth a shot.
 
Yeah, that's right. I'm a little unclear on the flow. Usually when doing a submit, you go to a different page, but sounds like you're staying on the same page. Do you have this up somewhere you can provide a link to? Also, another thing to try, take the code inside the onsubmit and put in where you were having errors, or is that what you tried before?

Edit: Something to try, though I don't have a way to test it myself. With my proposed code before, on the onsubmit, preface the code in quotes with this.submit(); This may end up ignoring the second code snippet that empties the text field, but worth a shot.

Angel: in name and deed!!

The solution was the following: giving the script as the onSubmit event wasn't right, even giving a this.submit() before the script. So I added again as a standalone <script>...</script> after the form, and finally it went ok. The silly thing is that I already tried that before, but i was giving the id="Messaggio" to a wrong (but really similiar, crappy written code!) textfield. I really owe you a lot man, kudos to you!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.