473,324 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Trouble using 'return' charachter as a trigger for ajax request

bugboy
160 100+
I need to change the content of a div using ajax when i hit the 'return' key on my keyboard. How do i get js to aknowledge the 'return' character? chr(13) doesn't seem to work.
Thanks!

Expand|Select|Wrap|Line Numbers
  1. function handle_textarea(t, n)
  2.     { 
  3.     var val=t.value;
  4.     var the_length=value.length;
  5.     var last_char=val.charAt(the_length-1);
  6.  
  7.     if (last_char=='chr(13)')
  8.         {
  9.         xmlHttp=GetXmlHttpObject()
  10.         if (xmlHttp==null)
  11.              {
  12.              alert ("Browser does not support HTTP Request")
  13.              return
  14.              }
  15.         var url="new_row.php"
  16.         url=url+"?row_num="+row_num
  17.         url=url+"&rand="+Math.random()
  18.         xmlHttp.onreadystatechange=list_stateChange('list_id')
  19.         xmlHttp.open("GET",url,true)
  20.         xmlHttp.send(null)
  21.         }
  22.     else
  23.         {
  24.         resize_textarea(t, n);        
  25.         }
  26.     }
  27.  
Nov 7 '08 #1
5 1265
rnd me
427 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. function el(tid) {return document.getElementById(tid);}
  2.  
  3.     el("textAreaID").onkeydown=function(e){ 
  4.         e=e||window.event;
  5.         var kc = e.keyCode; 
  6.         if(kc==13){
  7.             alert("Enter key pressed");
  8.         }
  9.     }
  10.  
Nov 7 '08 #2
bugboy
160 100+
Ok so i put the function in my include file and the function call into script tags in my page and now i have another problem. There is another onkeydown event that no longer works... oh.. maybe i'll try including it in the same call but as an else.. since if return is hit it doesn't need to work.. else it does..
Nov 7 '08 #3
bugboy
160 100+
Ok Cool, it works! Except that i only want the event to trigger if i hit return as the last key stroke in the textarea value. In other words if someone hits return in the middle of an existing sentence in the textarea then i don't want it to trigger.

This is what i'm trying but i can't quite figure out what's wrong with it.. any additional help would be really appreciated!

Expand|Select|Wrap|Line Numbers
  1.         el(\'textarea_id\').onkeydown=function(e)
  2.         { 
  3.         e=e||window.event;
  4.         var kc = e.keyCode; 
  5.         var val=document.getElementById(\'textarea_id\').value;
  6.         var the_length=value.length;
  7.         var last_char=val.charAt(the_length-1);
  8.         if(kc==13 && kc==last_char)
  9.             {
  10.             new_row(\'1\')
  11.             }
  12.             else
  13.             {
  14.             resize_textarea(this, \'0\')
  15.             }
  16.         }
Nov 7 '08 #4
rnd me
427 Expert 256MB
yeah, that's gonna severely complicate things.

in firefox, you can throw the code in an if statement:

where txt is the textarea object:

if(txt.value.length == txt.selectionStart){ //do the submit stuff here }

for others and IE, it a bit more than that.
Nov 7 '08 #5
bugboy
160 100+
Thanks for the help :)
Nov 8 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Tom | last post by:
Hi, I am working on a project where I want to simultaneously launch a link using my own registered protocol and simultaneously send an AJAX request to the server. Now the way I have come up...
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
3
by: itp | last post by:
I have moved to Matt Kruse's Javascript Toolbox. It has some great examples to get you going quickly! Unfortunately all the examples are based on a form/submit model. I would like to try using...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
2
by: lintolawrance | last post by:
hai friends, i need some help from u.i am trying to work with Ajax.i done some codes for developing dropdownlist using ajax.but it doesn't work.please help me to develop it. ...
1
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.