LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 August 10 2011

mighthappen
Member

Needed a simple javascript/ajax code!

I'm not good at javascript, and most of my javascript codes I get are somewhere on the web. However, I wasn't able to find the desired code, so Please someone do care to write it for me

I just need the code to identify(while I'm writing into a textarea) a character(let's say %) and when it finds it, I want to execute a php code(which I already did)...
Thank you all very much and any help would really be appreciated

Offline

#2 August 10 2011

Ra8
Member

Re: Needed a simple javascript/ajax code!

This will identify the key that you pressed and make an event out of it, i adjusted it to alert when you press %, you can change the charCode==37 (37 is %) to another charcode key.

Offline

#3 August 10 2011

Joe
Member

Re: Needed a simple javascript/ajax code!

Executing a server-side script like php is going to take a bit more than listening to an event. You're going to have to use AJAX.

If you're new to it, give JQuery a try.

Offline

#4 August 10 2011

mighthappen
Member

Re: Needed a simple javascript/ajax code!

Ra8 Could you please give me the code to the script you did?
And I guess you guys misunderstood what I was searching for.
It's like facebook's status updates, when You wanna tag someone, you just add @ and automatically it generates the available users in the database. thanks again!

Offline

#5 August 10 2011

Ra8
Member

Re: Needed a simple javascript/ajax code!

mighthappen wrote:

Ra8 Could you please give me the code to the script you did?

It's JS... you can just right-click view source... anyway:

<textarea name="rene" cols="40" rows="3" onkeypress="on_up(event)"/></textarea> 
<br/>CharCode of last key:<span></span> 
<script> 
function on_up (evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	document.getElementsByTagName("span")[0].innerHTML=charCode;
	if(charCode==37){alert("You just pressed %");}
}
</script>

the @ is 64

Offline

#6 August 11 2011

mighthappen
Member

Re: Needed a simple javascript/ajax code!

Thank You Ra8

Offline

Board footer