Click to See Complete Forum and Search --> : Submit Button Help
I have this chat form that has a send button:
http://kd7pyo.infinitypages.com/chat/
It also has a message box and you will notice if you type a message you have to hit the send button because if you just hit the return key it will add another line. Is it possible to have it so when you hit the return key it will do the same action as the send button does? Instead of put another line I want it to send if you hit the return key. Thanks for any help. :D
I want a textarea because I still want them to be able to type long sentances and see what they are typing. So is it possible to have a textarea and still do what I want?
Originally posted by Dave Clark
Try something like this:
<textarea name="myText" onkeydown="
var key = (window.Event) ? event.which : event.keyCode;
if (key == 13) this.form.submit();
return true;"></textarea>
Dave
Actually, if you look at the code, you'll see that it uses Javascript to submit a hidden form in the IFrame. So instead of this.form.submit(); it would be top.iframeName.formName.submit();
[J]ona
That's cool. Just thought I'd say something so that Mjdimick doesn't end up confused about why it doesn't work, when the code is actually fine. :)
[J]ona
Jona,
And that will also still allow the send button too? So they can submit by hitting the send button AND by hitting the return key!
Originally posted by mjdimick
Jona,
And that will also still allow the send button too? So they can submit by hitting the send button AND by hitting the return key!
Yup.
[J]ona
Originally posted by Dave Clark
Actually, Jona (now that I think about it), the code I posted will work perfectly fine -- as is -- because what I supplied goes directly in the FORM that is to be submitted. Your code, on the other hand, is probably more in conjunction with the SEND button (which I haven't looked at) and, therefore, your code will not work in the scenario I previously posted. In other words, the SEND button does not have to be changed to use the code I posted.
*Thinks about it.* Actually, Dave (now that I think about it), the code you posted will work prefectly fine -- as is -- because what you supplied goes directly in the FORM that is to be submitted. My code, on the other hand, is probably more in conjunction with the SEND button (which you haven't looked at, probably) and, therefore, my code will not work in the scenario you previously posted. In other words, the SEND button does not have to be changed to use the code you posted.
:D:D:D
[J]ona
Ok, just now got back to see my post. Hmm... Wow! In all the confusion I lost which way I should do it. Which method should I use? Jona's or Dave's? God you guys are so good you can have fun while doing this! I have to have to think really hard usally, but I suppose thats just cause I'm so dumb. Lol... :p
Dave's method will work fine.
[J]ona
Well I tryed dave's method but it did not work. Don't forget I also have another function that dose something on keydown with my textarea already. Maybe thats inerfering with the one you had me try just now. After I inserted it and went to the page and tryed it all it does is disable the send button when I type the return key. We have that other thing already that disables it when you insert a return so I think thats what is inerfering. Is there another way to do this?
Well I just tried what Dave said and all it does is flicker the page and then add a whole bunch of garbage to the end of the link in the address bar of IE, but overall it dosn't even add the post. I need to know if there is another way? I'm running IE6. I want for this to be usable for as most browsers as possible. Thanks. :)
Yes, I put the code in exactally as you posted it on the forum. I changed no part of it. I changed it back though so it will still be operational for my visitors. I wunder what I could be doing wrong?
I changed my mind. I decided that I don't want that. I just wish I could figure out how to make it so the send button gets re-disabled if you click anywhere else. You notice that when you go to the page the send button is disabled then when you click inside the textarea the send button becomes enabled. I want it so when you click back outside of the textarea the send button gets re-disabled. Is this possible?
Ok, thanks anyway! You've been a big help.
:D (I will take answers from anybody else.) :D
Originally posted by mjdimick
I just wish I could make is so that the send button gets re-disabled when you click anywhere else.
You would use onBlur="this.form.elements[1].disabled=true;"
[J]ona
I inserted the exact code you gave me into my send button, but its not working. I'll click somewhere else and it dosn't disable the button. Was I suposed to insert that into the send button? Is there something I would have to chage for it to work on my form? Thanks for your help. ;)
Originally posted by mjdimick
Was I suposed to insert that into the send button?
Actually, you need to put it in the TEXATAREA. :)
[J]ona