Solved

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

Posted on 2004-04-24
9
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

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…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
Suggested Courses

632 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