473,772 Members | 3,712 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is it possible to force re-avaluating/re-parsing of HTML?

Hi,

Ran into the following problem while trying to have a code to
attach a Virtual Keyboard to any user's form:

User clicks a button and my JavaScript changes outerHTML
of say <textarea - adding things like ONCLICK='saveCa ret(this)'
etc. and it also tries to save any text that user could've entered
before the button press.

a) Value - (already typed text) is not assigned back
b) outerHTML is still the same - both in alert() text and via
javascript:x=do cument.body.inn erHTML.replace(/</g,'&lt;').repla ce(/\n/g,'<br>'); document.body.i nnerHTML = x;
The code is simple so I wander whether we have a way to force HTML to be
re-avaluated/re-parsed via a button click

(if I do the same via <script....</scriptline placed above the button
then everything is OK - because HTML is being changed _before_ the
page load is over)

=============== =============== =========
function vkb_addAttribut es(obj)
{

var obj_value = ""; if (obj.value != "") obj_value = obj.value;
var kA=" onFocus='vkb_tx tControl=this;' OnSelect='vkb_s aveCaret(this)' ";

var obj_HTML = obj.outerHTML;
var pos = obj_HTML.indexO f('>');
var part1 = obj_HTML.substr ing(0,pos);
var part2 = obj_HTML.substr ing(pos);
obj.outerHTML = part1 + kA + part2;

obj.value = obj_value;
}
=============== =============== ===============

Thanks,
Paul
Sep 25 '06
51 4425
Hi,

fjanon wrote:
>
I am not sure why you need to modify the HTML to add a JS event
handler. Just add the event handler in JS like this:

myelement.onloa d = myfunction;

function myfunction()
{
}
What does "onload" means? Page's onload? Is it "IE-only" method?

I don't need to do anything on "onload" - I need to _modify_
text inout fields by adding some evenhandlers to them:

Say a page has <textarea and/or <input type-text objects
and my Virtual Keyboard needs to "attach" itself to those input
fields - for them to have the following eventhandlers:
onFocus='vkb_tx tControl = this;' OnSelect='vkb_s aveCaret(this)' OnClick='vkb_sa veCaret(this)' OnKeyUp='vkb_sa veCaret(this)'

--
Regards,
Paul Gorodyansky
"Cyrillic (Russian): instructions for Windows and Internet":
http://RusWin.net
Russian On-screen Keyboard: http://Kbd.RusWin.net
Oct 5 '06 #11
Paul Gorodyansky wrote:
Hi,

fjanon wrote:
>>I am not sure why you need to modify the HTML to add a JS event
handler. Just add the event handler in JS like this:

myelement.onl oad = myfunction;

function myfunction()
{
}


What does "onload" means? Page's onload? Is it "IE-only" method?

I don't need to do anything on "onload" - I need to _modify_
text inout fields by adding some evenhandlers to them:
Which you can do in your window.onload() method.

--
Ian Collins.
Oct 5 '06 #12
Ian Collins wrote:
>
Which you can do in your window.onload() method.
It's not _my_ page - I am preparing the code of my Virtual Keyboard
for _other_ people to use on their sites/forums - often their
pages are PHP-generated.

It's why I don't whant to use things like
<body onload...>

It's too intrusive, IMHO.

But it's not the point any way - there is no difference between my
current approach - asking them to insert the following line
below their input fields -
<script type="text/javascript">vkb _Init();</script>
and asking them to insert
onload...
stuff to their <body statement.

In both cases I cause their objects to be modified EVEN if
a button that calls Virtual Keyboard will never be pressed!

I am trying (and asking here) to add evenhandlers to some one's
input fields in a different way - ONLY if an end user click
Virtual Keyboard button - I want, during the very first click -
do the same that vkb_Init(); does currently - add several
eventhandlers (onfocus, onkeyup, ...) to all text input fields -

but it does NOT work - "too late" - the page has already been loaded
and browser does not see those added evenhandlers
(please see my today's answer to Jake above)

--
Regards,
Paul Gorodyansky
"Cyrillic (Russian): instructions for Windows and Internet":
http://RusWin.net
Russian On-screen Keyboard: http://Kbd.RusWin.net
Oct 5 '06 #13
Paul Gorodyansky wrote:
Ian Collins wrote:
>>Which you can do in your window.onload() method.


It's not _my_ page - I am preparing the code of my Virtual Keyboard
for _other_ people to use on their sites/forums - often their
pages are PHP-generated.

It's why I don't whant to use things like
<body onload...>

It's too intrusive, IMHO.

But it's not the point any way - there is no difference between my
current approach - asking them to insert the following line
below their input fields -
<script type="text/javascript">vkb _Init();</script>
and asking them to insert
onload...
stuff to their <body statement.

In both cases I cause their objects to be modified EVEN if
a button that calls Virtual Keyboard will never be pressed!

I am trying (and asking here) to add evenhandlers to some one's
input fields in a different way - ONLY if an end user click
Virtual Keyboard button - I want, during the very first click -
do the same that vkb_Init(); does currently - add several
eventhandlers (onfocus, onkeyup, ...) to all text input fields -

but it does NOT work - "too late" - the page has already been loaded
and browser does not see those added evenhandlers
(please see my today's answer to Jake above)
Ah, OK, I missed the bit about other code.

DOM manipulation can an will take effect when applied. Have you tried
just setting the target element's onclick property?

--
Ian Collins.
Oct 5 '06 #14
Ian Collins wrote:
>
...
DOM manipulation can an will take effect when applied. Have you tried
just setting the target element's onclick property?
Yes, it was 1st thing I tried to use but could not find a way to do it
and this is why started to use outerHTML to add onclick onfocus onkeyup
to the input fields HTML code.

Don't remember now where I looked - I do remember that I searched
Google exactly for that -
"set element's onclick property" - but found only something like this -

http://www.devguru.com/Technologies/...ript/10846.asp
or this: http://bton.com/tb16/jsref/object4.html#anchor540568

where I could not find what I was looking for - how to _add_
onclick="myFunc tion", onfocus="myFunc tion", onkeyup="myFunc tion",
onkeypress="myF unction".

I saw some other methods but they were "Internet Explorer only".

--
Regards,
Paul
Oct 5 '06 #15
Paul Gorodyansky wrote:
>
I saw some other methods but they were "Internet Explorer only".
I meant the following (which, being it cross-browser thing, would be
exactly what I need):

<SCRIPT LANGUAGE=javasc ript FOR=textEl EVENT=onfocus>
myFunction(even t);
</SCRIPT>
--
Regards,
Paul
Oct 5 '06 #16
Paul Gorodyansky wrote:
Ian Collins wrote:
>>...
DOM manipulation can an will take effect when applied. Have you tried
just setting the target element's onclick property?


Yes, it was 1st thing I tried to use but could not find a way to do it
and this is why started to use outerHTML to add onclick onfocus onkeyup
to the input fields HTML code.

Don't remember now where I looked - I do remember that I searched
Google exactly for that -
"set element's onclick property" - but found only something like this -

http://www.devguru.com/Technologies/...ript/10846.asp
or this: http://bton.com/tb16/jsref/object4.html#anchor540568

where I could not find what I was looking for - how to _add_
onclick="myFunc tion", onfocus="myFunc tion", onkeyup="myFunc tion",
onkeypress="myF unction".

I saw some other methods but they were "Internet Explorer only".
What exactly is the sequence of events you use? The user loads a page
(any page?) and then does something to add a virtual keyboard, how?

--
Ian Collins.
Oct 5 '06 #17
Ian Collins wrote:
>
What exactly is the sequence of events you use? The user loads a page
(any page?) and then does something to add a virtual keyboard, how?
Currently I offer site owners or forum Administrators the following
(seeing on http://RusWin.net/readme_e.htm and say
on working example at http://RusWin.net/vkbFly2e.htm ):

1) Add one line to <headwith vkb_load.js
(this .js loads then other .js and several .css 'silently' to the
<head>)

2) Below last input field of the form (it could be numerous <textarea
and/or <input type=text fields) insert the line

<script type="text/javascript">vkb Init(document.i nputForm);</script>

that function successfully adds onfocus, onkeypressed, and other I need
to
the text input field (because it's executed while the page is still
under "evaluation " by the browser, so browser does notice those
additional evenhandlers on text fields)

If I copy this into the address bar (found somewhere on the Web)
javascript:x=do cument.body.inn erHTML.replace(/</g,'&lt;').repla ce(/\n/g,'<br>');
document.body.i nnerHTML = x;

then I see my changes! That is, I see onfocus=, onclick=, etc. in text
fields' HTML

3) Add a line that user of their site/forum woudl use to call Virtual
Keyboard, say
<BUTTON TYPE=button onclick="blur() ; showKbd(); return false;" .........

=============== =============== =============

The above works just FINE - as working examples show.

But I created this thread to try to do the same DIFFERENT way -
without item (2) - to avoid changing objects 'just in case' -
who knows may be a user never clicks on Keyboard button -

instead of (2) I wanted to execute that vkb_Init() which adds
evenhandlers only when a user clicks on Keyboard button.

I tried and it failed and it's why I opened this thread -
looks like when I do the additions after a user clicks the button,
it's too late - the page has already been evaluated by the browser
and browser does NOT see the additions (onfocus, onclick,...) I made
in vkb_Init() when it's called after a user clicks the button -
nothing works and also page's source does not show those additions
if I paste the "look at source" line into the address bar.

So I am asking, "How to force a browser to re-evaluate HTML code
of the forms' elements".

But if it's not possible:

may be it does not work because I do those additions via
outerHTML of the objects. Is there another way to add eventhandlers?

outerHTML was the only (cross-browser) thing I found when I used
Google for something like, "Add textarea properties".

Because again, this thing (which is what I want) is IE-only:
<SCRIPT LANGUAGE=javasc ript FOR=textEl EVENT=onfocus>
myFunction(even t);
</SCRIPT>
--
Regards,
Paul
Oct 6 '06 #18
Paul Gorodyansky wrote:
Ian Collins wrote:
>>What exactly is the sequence of events you use? The user loads a page
(any page?) and then does something to add a virtual keyboard, how?

I tried and it failed and it's why I opened this thread -
looks like when I do the additions after a user clicks the button,
it's too late - the page has already been evaluated by the browser
and browser does NOT see the additions (onfocus, onclick,...) I made
in vkb_Init() when it's called after a user clicks the button -
nothing works and also page's source does not show those additions
if I paste the "look at source" line into the address bar.

So I am asking, "How to force a browser to re-evaluate HTML code
of the forms' elements".

But if it's not possible:

may be it does not work because I do those additions via
outerHTML of the objects. Is there another way to add eventhandlers?
Could be, I've never tried that.

Just do theTextarea.onf ocus = yourMethod();

--
Ian Collins.
Oct 6 '06 #19
Ian Collins wrote:
>

may be it does not work because I do those additions via
outerHTML of the objects. Is there another way to add eventhandlers?
Could be, I've never tried that.

Just do theTextarea.onf ocus = yourMethod();
Thanks!
Looks nice and simple - why didn't I find such examples when was
looking for the way to add evenhandlers to text fields?

Will go now and try that.

--
Regards,
Paul
Oct 6 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1566
by: infidel | last post by:
I may have found the source of my infinite loop when importing kid modules from my cherrypy server. Here is some code from the autoreloader module of cherrypy: def reloader_thread(): mtimes = {} def fileattr(m): return getattr(m, "__file__", None)
3
6356
by: Clark Spencer | last post by:
I have built a small integration app using VS .NET 2003 that extracts orderinformation from a 'webshop'. Extracting the orderinformation works fine. Appending the order elements in the XmlDocument was also done in a jiffy. The final step is to save the document to disk and then ship it to another system using ftp. The xml orderfile produced must fit a set specification of the recieving system. That specification states that empty elements...
5
1174
by: craig | last post by:
Assume that you have a User object, which abstracts an authenticated user of your application. It has some properties such as UserID, FirstName, LastName, etc. and a method LogOut(); The LogOut method logs the user out of the application. If the LogOut() method is successful, the user is logged out and the User object should no longer be valid. Is there a way to allow the LogOut() method to force the reference that is being held to the...
2
2969
by: Steve Franks | last post by:
According to the docs you tell ASP.NET to use cookieless sessions by setting a value in the config.web file. However, what if I wanted to determine at run time whether or not I wanted to use cookieless sessions for a particular user, and if so, I'd instruct ASP.NET to turn on cookieless sessions for a particular user session. Is this possible? For example I want to use cookie based sessions by default for all users. But if a user has...
1
2907
by: nightowlky | last post by:
Is it possible to force a file (opened on a local drive of a machine) to be closed in order that it may be written to with updates?
1
3912
by: Mark A | last post by:
DB2 ESE 8.2.3 (FP10) for Linux We are experiencing a connection hang of 10 - 15 minutes in the following HADR and automatic client reroute scenario: 01 server is primary database 02 server is standby database a. applications connected to database on 01 server b. shutdown 01 server
11
1493
by: gregory_may | last post by:
Is it possible to force a limit on the amount of CPU a task is taking? I am thinking of writing a simple app that will let me force other applications to "be nice" by only using so much CPU. Is this possible ... does anything like this exist?
0
2662
by: comp.lang.php | last post by:
I have a form that when you click the "Generate Report" submit button, it will force download a CSV file, required for this project. On the very same page you also have a "Search" submit button, when you press it it should generate search results in a new page. However, when you click the "Generate Report" submit button, the moment you try to THEN click the "Search" submit button, the "Search" submit button NEVER goes to a new page but...
0
858
by: scoe | last post by:
In designing a application to update firmware, I require to reset the hardware. Is their any command or method to force a reset of the device.
6
3506
by: Hubert Fritz | last post by:
Hello, I fear I want to have something which is not possible in C++. How is it possible to define a base class so that the derived class is forced to contain a static member variable, which can be used by static member functions of the base class? Something like virtual static XClass* pXClass; /* pXClass shall be pure virtual, so not static in base class, but
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.