Question

How to detect newline (\n) at runtime (AJAX TYPE)?

Asked by: tom_mk

hi,

i'm quite new to javascript and AJAX,
but i know java, but haven't really used it for quite a while,
mostly i only do PHP,MYSQL

however, i think that my question is mostly related to javascript,
that's y i postig my question here

I'm trying to implement a barcode reader system
using php, mysql , javascript and AJAX

I'm trying to detect \n which will b passed from the barcode reader,
and then something (some action) will be invoked.
for example,  i will have one text field display,
the field will be cursored (prompted)

i'll have barcode reader,
scan one barcode,
barcode (number) is then inputted into the system
(which normally, the number that has been read will b appended by \n)
then , the new field will then pop out (using CSS, JAVAscript)

what i don't know how to do is the part that is need to detect the newline sysbol
and then another textfield will b pop out

i do believe that i have to use javascript to detect it,
but i just don't know how to start,
i've been searching for this for a few days, already.

any help on this would b realy appreciate.

Tom

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-12-22 at 21:24:08ID22102179
Tags

javascript

,

detect

,

newline

Topic

JavaScript

Participating Experts
4
Points
250
Comments
19

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Newline (XML)
    what should i write in my xml documents to make a newline tag en flash ? hope you understand me ;) Regards. Bo Sørensen aka. EFloW
  2. CSS, PHP and MySQL??
    I have created a css file which contains php, as follows: <style type="text/css"> <!-- <?php include_once("Cconnection.php"); $obconnect = new connect_class(); $obconnect->connection(); $obconnect->dbconnect(); $SQL = "...
  3. N-Tier PHP + MySQL + XML + XSLT + Ajax + XHTML +…
    Hello, Where can I find out more about the design and structure of such web application, that implements all of the above efficiently together. To be more specific, I'm concerned with: 1) Database driven XML/XSL stuff. (And not necessarily MySQL, if there are better free s...
  4. How to make a CRUD Datagrid in PHP using only PHP, MyS…
    Hello All, I am building a web app in PHP/MySql on my Mac 10.3 powerbook. I know PHP & MySql, and am learning CSS, Javascript and Ajax. I want to be able to create a Datagrid in PHP much like the datagrid function of ColdFusion, where I can submit a query, and it will o...
  5. AJAX MySQL validation
    I'm looking to use AJAX to check if a username or e-mail exists in a MySQL table for when new users signup to an application I've created. It is feasible to do this with AJAX? I just need to splurt out to a hidden div that the username or password already exists. If it's okay...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: basicinstinctPosted on 2006-12-22 at 21:47:14ID: 18190903

Well you can use String.indexOf("\n") just like in Java, or you can use String.match(/\n/)

 

by: tom_mkPosted on 2006-12-22 at 21:51:43ID: 18190907

but the problem is, how can i do he keep checking?

it's like when the number has been read,
that instant the number is  inserted into the textFeild
and then another textField supposed to pop out in that instant.

so basically i need something to keep checking all the time..

any example 'basicinstinct' ?

Tom

 

by: b0lsc0ttPosted on 2006-12-22 at 23:16:41ID: 18190974

tom_mk,

I don't see how AJAX is involved.  It seems like you have the cursor in the text field and then have it get the barcode reader data.  Is that correct or is there more to it?

If so, the first challenge is getting an event to notice the barcode data.  The browser has a number of events to use for keyboard, mouse, etc but the barcode data seems to be ignored.  Take a look at the question below where I am working with another member on a similar problem.

http:Q_22087672.html

Finding a new line character in a string is easy and you javascript can create a new text field and put focus on that field.  I can help with that but the first challenge would be to find an event that works.  You could try an onkeyup event like the one below in the text field to see if it detects the scanner.

onkeyup="alert('key up'); return false;"

Let me know the results if you run that test or other events.  We can work from there if the browser can detect and get the data.  Let me know if you have any questions or need more information.

b0lsc0tt

 

by: tom_mkPosted on 2006-12-22 at 23:53:28ID: 18191022

hi,
i've tried on what you suggeseted,
eveything mostly works, except one thing.

the function won't start successfully, until i have a space bar after \n

u will c what i 'm saying after u tested it out.. i guess
so i uploaded the source to my homepage

http://www.tom1789.com/javascript/tmp1.html

 

by: tom_mkPosted on 2006-12-22 at 23:53:43ID: 18191023

i don't know if i missing anything

 

by: b0lsc0ttPosted on 2006-12-22 at 23:59:37ID: 18191030

What function?  Do you mean the alert?  I don't have a scanner I can use to test this so I need to go with your test and feedback.

Did you press the space bar?  You can't press a key on your keyboard to test this.  You can click with your mouse to put the cursor in the input box but then just use the reader.  Did you try the onkeyup event or a different one?

Thanks for clarifying what you did and what happened.  Let me know.

bol

 

by: tom_mkPosted on 2006-12-23 at 00:26:43ID: 18191056

i don't have barcode reader with me now either,
that's y i tried to type something like "234234\n" then space.

to see if this will work,
i do believe that this might b the most closed simulation that i could do.
what u think?

TOM

 

by: thirdPosted on 2006-12-23 at 01:55:48ID: 18191153

my version,

<html>
<head>
<script type="text/javascript">
var timer;

window.onload = function(){
  focusField();
  timer = setInterval('stripNewline(document.frm1.fname)', 300);
}

function stripNewline(obj){
  if(obj.value.indexOf('\\n') > -1){
    obj.value = obj.value.replace('\\n', '');
    //clearInterval(timer);
      //obj.form.submit(); //if this needs to be submitted
  }  
}

function focusField()
{
      var uu = document.getElementById("fname");
      uu.focus();
}
</script>
</head>
<body>
<form name="frm1" method="post" action="" onsubmit="return ">
Barcode Number :
<input type="text" name="fname" id="fname">
<br />
<a href="tmp1.html">REFRESH</a></form>
</body>
</html>

 

by: tom_mkPosted on 2006-12-23 at 10:14:27ID: 18192388

thanks for the code THIRD,
however, i still don't see how it can solve my problem,

or am i missing anything?
Please point out,
Tom

 

by: tom_mkPosted on 2006-12-23 at 11:13:59ID: 18192537

i don't understand this part
<form name="frm1" method="post" action="" onsubmit="return ">

wat does > onsubmit="return " do?
can any1 explain?

Thx a lot
Tom

 

by: tom_mkPosted on 2006-12-23 at 12:11:49ID: 18192651

new version with the help from
> http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/

live demo (with not working as i expected) : http://www.tom1789.com/javascript/tmp1.html

<html>

<head>
<script type="text/javascript">
function upperCase(x,box)
{
      // to upperCase all the character
      var y=document.getElementById(x).value;
      document.getElementById(x).value=y.toUpperCase();

      var sentence = y;

      // to detect the ending and increment the form      
      if ((sentence.indexOf("\n")!=-1) ||  (sentence.indexOf("\N")!=-1) )
      {
            // create another DIV and put textField into it
            var ni = document.getElementById(box);
            var numi = document.getElementById('numField');
            var num = (document.getElementById("numField").value -1)+ 2;
            numi.value = num;
            
            var divIdName = "my"+num+"Div";
            var newdiv = document.createElement('div');
            newdiv.setAttribute("id",divIdName);
            
            newdiv.innerHTML = "<input type='text' id='"+divIdName+"' onkeyup='upperCase(this.id, 'target')'>";      
            ni.appendChild(newdiv);            
 
            // make new textField Focus
            var kk = document.getElementById(divIdName);
            kk.focus();
      }      
}

window.onload = function()
{
  focusField();
}

function focusField()
{
      var uu = document.getElementById("fname");
      uu.focus();
}


</script>
</head>

<body>

Barcode Number :
<input type="hidden" id="numField" value="0" />
<input type="text" id="fname" onkeyup="upperCase(this.id, 'target')">
<br />
<div id="target">
</div>
<a href="tmp1.html">REFRESH</a>
</body>

</html>

 

by: thirdPosted on 2006-12-23 at 22:41:10ID: 18193793

sorry tom i have completely misread your question. my bad... ;-)

 

by: thirdPosted on 2006-12-23 at 23:59:23ID: 18193863

I still have time to code so I went back. Merry Christmas! ;-)

try this,

<html>
<head>
<script type="text/javascript">
var timer;
var fieldCount = 1;

window.onload = function(){
  focusField();
  timer = setInterval('stripNewline(document.frm1.elements["fname" + fieldCount])', 100);
}

function stripNewline(obj){
  if(obj.value.indexOf('\\n') > -1){
    var newField = obj.cloneNode(false);
      newField.name = 'fname' + (fieldCount + 1);
      newField.id = newField.name;
      newField.value = '';
      obj.parentNode.appendChild(document.createElement('<br>'));
      obj.parentNode.appendChild(newField);      
      newField.focus();
      fieldCount++;
  }  
}

function focusField()
{
     var uu = document.getElementById("fname1");
     uu.focus();
}
</script>
</head>
<body>
<form name="frm1" method="post" action="" onsubmit="">
Barcode Number :
<input type="text" name="fname1" id="fname1">
</form>
<br />
<a href="tmp1.html">REFRESH</a></form>
</body>
</html>

 

by: ahoffmannPosted on 2006-12-24 at 14:01:38ID: 18194969

> i'll have barcode reader,
Where is the barcode reader conected?
How do you pass the data from it to the browser?

 

by: tom_mkPosted on 2006-12-24 at 21:59:56ID: 18195524

- ahoffmann
USB, i think, but then the value which will b read will b input liked the KB

- third
ur code works perfectly,
however, i do have question..

y my method doesn't work, when i try to set focus on the new just-borned textField.

Tom

 

by: tom_mkPosted on 2006-12-24 at 22:04:25ID: 18195535

Merry Christmas everyone

 

by: thirdPosted on 2006-12-24 at 22:30:49ID: 18195593

the div and the input has the same ID. the browser is focusing on the div not on the input. there are other errors on your code. I strongly recommend you use my method.

This is my Christmas present to you, Tom! ;-)

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...