Solved

I need to empty a textarea when the user submit the form

Posted on 2004-04-24
9
299 Views
Last Modified: 2006-11-17
I have a small rpg community. My chatrooms are written in php, but I have some problems with the submit message javascript. This is the form. First, it work only in IE and many players are unappy about that. In Netscape the form doesn't work, and not send the message on the chat. In IE when you use alt-tab for read another page or use some application (like an istant messenger), the message is automatically cancelled. There is a way to solve this problem emptying the text box only when you submit it? This is the actual form:

<form action="./Chattest01.php?frame=chat" method="post" target="chat" onsubmit="this.submit.focus(); this.message.focus(); return check(this);">
<input type="text" name="message" onfocus="this.value=''" size="50" value="Write here">&nbsp;<input type="submit" value="Invia" name="submit">
</form>

Thank You,
Alina Vlazhy
0
Comment
Question by:PrincessAlina
  • 5
  • 4
9 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10909252
Naming the submit button "submit" is a bad idea.
Better would be to name it "Submit"

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10909258
And the Netscape problem is shurely inside of the function check()
Can we see the code of check() function?
0
 

Author Comment

by:PrincessAlina
ID: 10909323
This is the function check. I never know the way this work.  

<script LANGUAGE="JavaScript">
<!-- Begin
function check(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="message") {
if (((tempobj.type=="text")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
}
}
}
}
if (!pass) {
return false;
}
else
return true;
}
// End -->
</script>
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PrincessAlina
ID: 10909431
I think is aboout blocking some filetypes, but never worked because I had to deactivate html tags with eregi_replace() in php to avoid some annoying players to put midis in the chatrooms or using fonts colors that are allowed only to game masters.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10909467
Check this:


<html>
<head>
<title>Chat</title>
<script LANGUAGE="JavaScript">
<!-- Begin
function check(theForm) {
  if (theForm.message.value=="") {
    return false;
  }else
    return true;
}
// End -->
</script>
</head>
<body>
<form action="./Chattest01.php?frame=chat" method="post" target="chat" onsubmit="return check(this);">
<input type="text" name="message" size="50" value="Write here" onfocus="this.value='';this.onfocus=null">&nbsp;<input type="submit" value="Invia" name="Submit">
</form>
</body>
</html>

0
 

Author Comment

by:PrincessAlina
ID: 10909492
The script works, except for the problem that the text area does not empty when the message is submitted.
0
 

Author Comment

by:PrincessAlina
ID: 10909525
Is possible to make it autoclearing when is submitted the message?
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 50 total points
ID: 10910795
Like this:


<html>
<head>
<title>Chat</title>
<script LANGUAGE="JavaScript">
<!-- Begin
function check(theForm) {
  if (theForm.message.value=="") {
    return false;
  }else{
    window.setTimeout("document.forms[0].message.value='';",100);
    return true;
  }
}
// End -->
</script>
</head>
<body>
<form action="./Chattest01.php?frame=chat" method="post" target="chat" onsubmit="return check(this);">
<input type="text" name="message" size="50" value="Write here" onfocus="this.value='';this.onfocus=null">&nbsp;<input type="submit" value="Invia" name="Submit">
</form>
</body>
</html>


0
 

Author Comment

by:PrincessAlina
ID: 10911364
It's working perfectly!! Thank you!

Alina Vlazhy
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question