Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-04-24
9
Medium Priority
?
313 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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

927 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