Solved

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

Posted on 2004-04-24
9
294 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now