473,395 Members | 1,574 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,395 software developers and data experts.

How to encapsulate a statement

Claus Mygind
571 512MB
I am creating an input field dynamically. I want to test to see if the user pressed the "Enter Key" to start processing. I seem to need 3 wrappers single quote ', double quote " and one more. Below are two attempts I have made to get around the limitation of only two delimiters. Neither works.

How can I write the code below so it is properly delimited?

example 1
Expand|Select|Wrap|Line Numbers
  1. td.innerHTML =    '<INPUT'+
  2.             ' type="text"'+ 
  3.             ' name="SEARCH"'+ 
  4.             ' id="SEARCH"'+
  5.             ' onKeyPress="if ( isEnter( event )) { onClick="psRequestData(this)" };"'+
  6.             ' />';
  7.  
example 2
Expand|Select|Wrap|Line Numbers
  1. var cInsert = 'onClick="psRequestData(this);"';
  2. td.innerHTML =    '<INPUT'+
  3.             ' type="text"'+ 
  4.             ' name="SEARCH"'+ 
  5.             ' id="SEARCH"'+
  6.             ' onKeyPress="if ( isEnter( event )) {'+cInsert+'};"'+
  7.             ' />';
  8.  
Jun 10 '08 #1
7 1525
acoder
16,027 Expert Mod 8TB
The problem is not just limited to delimiters (though that can be solved by escaping). Are you trying to set an onclick if enter is pressed? You'd be better off setting this in a function using txtbox.onclick = someFunction;
Jun 10 '08 #2
Claus Mygind
571 512MB
Yes I do have a function to actually handling the event when a key is pressed on the keyboard. I use that function other places and is not the source of my problem here.

The problem here is I am trying to write this input element dynamically (on the fly) and I seem to be using up the available delimiters.

Can you give an example of how the quotes would be escaped?
Jun 10 '08 #3
Claus Mygind
571 512MB
I should add, I want to see when and if the user is pressing the "Enter Key". So we are really testing every key stroke. I already have a "Go" button with the onClick event handler. This is a short cut which will enable the same action without the user leaving the input field.
Jun 10 '08 #4
acoder
16,027 Expert Mod 8TB
The escape character is \, so you can escape single quotes like this:
Expand|Select|Wrap|Line Numbers
  1. \'
However, you can't set an onclick like you have in your code (in an if statement). Set it in the isEnter function instead.
Jun 10 '08 #5
Claus Mygind
571 512MB
Well how then would I code this line

Expand|Select|Wrap|Line Numbers
  1. ' onKeyPress="if ( isEnter( event )) { onClick="psRequestData(this)" };"'
Perhaps what you are telling me the "onClick" is really not needed here. And it should be written like this.

Expand|Select|Wrap|Line Numbers
  1. ' onKeyPress="if ( isEnter( event )) { psRequestData(this) };"'
I really just want to execute the "psRequestData(this);" if the enter key was pressed.
Jun 10 '08 #6
Claus Mygind
571 512MB
Yep! that was the solution. I had copied the line from the Button's onClick event handler and forgotten to remove it in the onKeyPress event handler for the the text element.

Thanks for the help.
Jun 10 '08 #7
acoder
16,027 Expert Mod 8TB
You're welcome. Glad you got it working.
Jun 10 '08 #8

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

Similar topics

0
by: beyond | last post by:
does anyone knows, how to encapsulate pl/sql-packages into DAO-object (java)? we are considering to separate logic from data-structure in oracle. what are the technical problems /risks doing...
3
by: charliewest | last post by:
this is a very newbie question re: oop - pls excuse my ignorance: i have inserted in each of my asp.net web forms written using C# error handing code that i would like to encapsulate in one,...
5
by: Thorbjørn Jørgensen | last post by:
Hi How can I encapsulate a specific method from a specific object? I have some different object with different methods, and I would like that the object could put a reference to one of its methods...
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
1
by: Jason Huang | last post by:
Hi, In my C# windows form, is it possible to encapsulate a Label to an Image? If possible, how to do that? Thanks for help. Jason
2
by: kabradley | last post by:
Hello everyone. I have three reports that I would like to put into one main report. I tried creating the main report and then putting three seperate subreports in the detail section of the parent...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
4
by: nw | last post by:
Hi All, I currently have a vector of objects (lets call them MyObject). I want to perform various operations regularly on the whole vector, for example find the maximum, average, or operations...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.