Register FAQ/Rules Forum Spy Search Today's Posts Mark Forums Read

Welcome to the Mac Forums forums. Please read the FAQ if you have questions. Register to participate.

 
Go Back   Mac Forums > Special Interests > Web Design and Development
TouchArcade.com - iPhone Game Reviews and News

Reply
 
Thread Tools Search this Thread  
Old Aug 1, 2008, 02:53 PM   #1
Lorthirk
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>
Lorthirk is offline   Reply With Quote
Old Aug 1, 2008, 03:03 PM   #2
dalvin200
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:
function docOnLoad() {
document.input.Messaggio.value='';
}
that will clear the form value when the page has loaded up..

hope this helps
__________________
24" iMac "Penryn"; 2.8GHz, 4GB RAM, 500GB HDD, 8800GS
I luuurrvvveee my iPhone 3G 16GB
Search before you post: MRoogle
dalvin200 is offline   Reply With Quote
Old Aug 1, 2008, 03:31 PM   #3
Lorthirk
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.
Lorthirk is offline   Reply With Quote
Old Aug 1, 2008, 03:42 PM   #4
angelwatt
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.
angelwatt is online now   Reply With Quote
Old Aug 1, 2008, 05:47 PM   #5
Lorthirk
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.
Lorthirk is offline   Reply With Quote
Old Aug 1, 2008, 06:16 PM   #6
angelwatt
macrumors 601
 
Join Date: Aug 2005
Location: Dayton, OH
Quote:
Originally Posted by Lorthirk View Post
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" 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="">
...
angelwatt is online now   Reply With Quote
Old Aug 1, 2008, 06:38 PM   #7
Lorthirk
Thread Starter
macrumors member
 
Join Date: May 2007
Quote:
Originally Posted by angelwatt View Post
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" 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="">
...
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?
Lorthirk is offline   Reply With Quote
Old Aug 1, 2008, 06:53 PM   #8
angelwatt
macrumors 601
 
Join Date: Aug 2005
Location: Dayton, OH
Quote:
Originally Posted by Lorthirk View Post
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.

Last edited by angelwatt : Aug 1, 2008 at 07:06 PM. Reason: Added new idea
angelwatt is online now   Reply With Quote
Old Aug 2, 2008, 07:41 AM   #9
Lorthirk
Thread Starter
macrumors member
 
Join Date: May 2007
Quote:
Originally Posted by angelwatt View Post
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!
Lorthirk is offline   Reply With Quote

Reply

Mac Forums > Special Interests > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 01:42 PM.

Mac News | Mac Rumors | iPhone Game Reviews | iPhone Apps

Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright 2002-2009, MacRumors.com, LLC