|
|
| Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate. |
|
|||||||
| TouchArcade.com - iPhone Game Reviews and News |
![]() |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
macrumors member
Join Date: May 2007
|
Javascript: undefined value
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>
|
|
|
|
|
|
#2 | |
|
macrumors Demi-God
Join Date: Mar 2006
Location: Nottingham, UK
|
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 Quote:
hope this helps
__________________
24" iMac "Penryn"; 2.8GHz, 4GB RAM, 500GB HDD, 8800GS I luuurrvvveee my iPhone 3G 16GB Search before you post: MRoogle
|
|
|
|
|
|
|
#3 |
|
Thread Starter
macrumors member
Join Date: May 2007
|
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.
|
|
|
|
|
|
#4 |
|
macrumors 601
Join Date: Aug 2005
Location: Dayton, OH
|
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.
|
|
|
|
|
|
#5 |
|
Thread Starter
macrumors member
Join Date: May 2007
|
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.
|
|
|
|
|
|
#6 | |
|
macrumors 601
Join Date: Aug 2005
Location: Dayton, OH
|
Quote:
Code:
<form name="invio" action="input.php" method="POST" onsubmit="document.getElementById('Messaggio').value='';">
...
<input type=Text id="Messaggio" Name=Messaggio class=txtbox size=60
style="font-weight:normal;font-family:Verdana;font-size:8pt"
maxlength="2000" value="">
...
|
|
|
|
|
|
|
#7 | |
|
Thread Starter
macrumors member
Join Date: May 2007
|
Quote:
|
|
|
|
|
|
|
#8 | |
|
macrumors 601
Join Date: Aug 2005
Location: Dayton, OH
|
Quote:
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. Last edited by angelwatt : Aug 1, 2008 at 07:06 PM. Reason: Added new idea |
|
|
|
|
|
|
#9 | |
|
Thread Starter
macrumors member
Join Date: May 2007
|
Quote:
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! |
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|