Solved

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

Posted on 2004-04-24
9
297 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

776 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