hi there!
i need to perform an dynamism for an application that send txt messages to phone handset.the recipient(s) number(s) textbox can take a lot of comma separated number. so any time the user type a comma i can select the number written at the left of the comma, do ajax call validate that number and highlight that number if its destination is unsupported.my problem is how to get that. i mean get the number from the textbox. i've already implemented an action to be performed on comma keypress (if charCode==188) and split the value of the textbox.but it's a workaround and very bad for performance because it would call already checked numbers if the user keep on adding more numbers.
Need something that select only one number on comma keypress.Is that possible if yes can you share your experience?
thank you.By the way i use jquery the only problem is on the textbox side(for now )
I don't think you specifically need jQuery for this. If I understand you correctly, you want to be able to read just "789" from the following string:
123,456,789
Correct?
Look into the Javascript string functions. There are functions that can tell you the position of the last comma in a string, & others that then allow you to extract from that position on.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
actually i want this 233 if this 233, and this 344 if this 233,344 and so on.I 've come out with this but i's triggers by button onclick event.here is it.my concern is aslo performance during a stress and load test.i mean i need to optimise it. here is the code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" language="javascript" src="library/jquery-1.2.6.js"></script>
<script type="text/javascript" language="javascript" src="library/jqModal.js"></script>
<link rel="stylesheet" type="text/css" href="library/jqstyling.css" />
<style type="text/css">
.err { color: #ffffff}
</style>
<script language="javascript">
$().ready(function() {
//$('#inputtxt').keyup(function(e){
// var t = $(this).val();
// //var te = t.indexOf(",");
// //var to = t.substring(0,-1);
// //var ti = e.charCode;
// var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
// if(key== 188)
// $('#valid').html('<div >' +t+ '</div>');
// });
var i = -1;
$('#btn').click(function(){
var y = $('#inputtxt').val();
if(y.length!=0)
{
var n = y.substring(i+1,y.lastIndexOf(','));
i = y.lastIndexOf(",");
alert(i + ' ' + n);
}
});
});
</script>
<title>Document sans titre</title>
<body>
<input type="text" id="inputtxt" />
<input type="button" id="btn" />
<br /><div id="valid" style="border:1pt solid;border-color:#FF6600;"></div>
</body>
</html>
can you please look also the commented code and advise for the way i recognize the comma keypress event? thank you for this fast reply.really appreaciate it
thanks for the time you spend reading my code and for helping me out.i've come out with something similar to what i wanted to achieve.i'm not done with the validation yet but it shouldn't be a problem.but there is one thing that's not working as expexted and don't really know if it from the css or my jquery selector.in fact i want to display the numbers inside the div with the id valid but it just displays after it.i went to search on the net div positioning and others' code are just similar to mine for what's needed to be done.
here is my code