Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
Simple javascript; changing onkeypress (At least it sould be simple)
Old 10-01-2008, 10:26 PM Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I have two questions... the first one i have the webpage below... yegh very ulgy.. i would like to use javascript to change the javascript:function1() to
javascript:function2() in the onkeypress in the body tag of the html...

I have tried various things such as document.body.onkeypress = "javascript:function2()" and varations on that...
can someone tell me how to do this and tell me that the document.body.onkeypress actually refers to...

Thanks Much


HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<!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" xml:lang="en" lang="en">
    <head>
    <title>First Question</title>
        <script type="text/javascript">
        function1() { alert('function1'); }
        function2() { alert('function2');}
       </script>
    </head>
    <body onkeypress="javascript:function1()">
    </body>
</html>
Raisdead is offline
View Public Profile
 
 
Register now for full access!
Old 10-01-2008, 10:38 PM A diffrent simple problem with javascript and frames
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I have a Simple Framed Web site that will eventually be usefull... (I hope)

I would like to retireve the innerHTML of a ID ('footer') in website in a diffrent frame Thesse are srcs

index.html

HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"
   "http://www.w3.org/TR/html4/frameset.dtd">
<html>
    <head>
        <title>Spiders ewww...</title>
    </head>
    <frameset rows="1%,99%">
        <frame name="crkmes" src="removed software cracking site url" />
        <frame name="mypage" src="top.php" />
    </frameset>
</html>
top.php
HTML Code:
<SCRIPT language="JavaScript">
    function exec(){
  var html = parent.crkmes.document.getElementById('footer').innerHTML;
        alert(html);
    }  
</SCRIPT> 

<body">
<div id="test"><span id="archive"><img class="d"  /></span></div>

<a href="" onmouseover="javascript:exec();">test</a>

</body>
Thanks for trying to help... and thanks for helping if you do help

Last edited by chrishirst; 10-02-2008 at 09:05 AM..
Raisdead is offline
View Public Profile
 
Old 10-02-2008, 06:35 AM Re: A diffrent simple problem with javascript and frames
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Frames are very very very rarely useful and if the site "useful" but is in frames, it negates it's usefulness by making it unusable.

BUT only javascript function calls in the href attribute needs to be prefixed with "javascript:"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 06:36 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
same answer as in your other question.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 08:39 AM Re: A diffrent simple problem with javascript and frames
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I changed the
<a href="" onmouseover="javascript:exec();">test</a> to
<a href="" onmouseover="exec();">test</a>

and it is still unopperational

thank you for that piece of information though
Raisdead is offline
View Public Profile
 
Old 10-02-2008, 08:45 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I tried removing the javascript: on the onkeypress to just the function name and the


document.body.onkeypress = "function2()";

still does chnage the onkeypress in the <body> tag
Raisdead is offline
View Public Profile
 
Old 10-02-2008, 09:07 AM Re: A diffrent simple problem with javascript and frames
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
which browser? any error generated?

link? ( remove the reference to the illegal site first)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 09:08 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
both threads on same topic merged
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 09:14 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
functions are defined as

function functionName(parameters) {
actions to be done by the function;
}
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 07:34 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
this is the full html

index.php
HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<!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" xml:lang="en" lang="en">
    <head>
    <title>Apple IIe</title>
        <script type="text/javascript" src="Scripts/functions.js"></script>
    </head>
    <body onkeypress="contents()">
        <div id="main">
            <span id="loading">apple //e</span>
        </div>
    </body>
</html>
Scripts/functions.js
Code:
    function contents() {
        document.getElementById("main").innerHTML = '<div>HTML CUT FOR    UNDERSTANDING</div>' ; 
        document.body.onkeypress = "vcredits()";
    }
    function vcredits() {
         alert('2');
    }
Raisdead is offline
View Public Profile
 
Old 10-02-2008, 07:35 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
Firefox; chrome; ie 5-7; no error...
Raisdead is offline
View Public Profile
 
Old 10-02-2008, 09:20 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
javascript is case sensitive

onkeypress should be onKeyPress
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-02-2008, 10:44 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I changed the onkeypress on the javascript to onKeyPress and i still never get the vcredits() function to replace the contents() function on the <body onkeypress="contents()"> (proff is that i never get the alert('2'); message when i press a key...)

if this helps

current working html

HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<!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" xml:lang="en" lang="en">
    <head>
    <title>Apple IIe</title>
        <script type="text/javascript">
           function contents() {
          alert('contents');
            document.getElementById("main").innerHTML = '<div>HTML CUT FOR    UNDERSTANDING</div>' ; 
            document.body.onKeyPress = vcredits();
        }
        function vcredits() {
            alert('2');
        }
       </script>
    </head>
    <body onkeypress="contents()">
        <div id="main">
            <span id="loading">apple //e</span>
        </div>
    </body>
</html>

Last edited by Raisdead; 10-03-2008 at 09:13 AM.. Reason: Changing html to show error in next post
Raisdead is offline
View Public Profile
 
Old 10-03-2008, 05:11 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the function name should NOT be in quotes.

You are assigning a method to the event NOT a string
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-03-2008, 09:12 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
This executes the function right away I want it to wait till i press a key again other wise i would just put the function at the end of the contents() function...

I know i didnt say that in my message but now you know

i edited the html in the message above to represent the change





This might help or might not...


I put the following line in the beginning of the contents() function

alert(document.body.onKeyPress);

i received an alert that said undefined the first time

then every time i press a key on the same page it says vcredits()

Last edited by Raisdead; 10-03-2008 at 09:17 AM.. Reason: adding content
Raisdead is offline
View Public Profile
 
Old 10-03-2008, 09:38 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I want it to wait till i press a key again other wise i would just put the function at the end of the contents() function...
For that you need to use the onKeyUp event to set the body.onKeyPress to a new function, otherwise it will execute straight away because (obviously) there is a key down.

Quote:
alert(document.body.onKeyPress);

i received an alert that said undefined the first time

then every time i press a key on the same page it says vcredits()
As it would. It is displaying the name of the function assigned to the object.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-03-2008, 05:49 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
I still get the 2 two alerts in a row meaning that the functions are executing back to back

current code

HTML Code:
<?xml version="1.0" encoding="utf-8"?>
<!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" xml:lang="en" lang="en">
    <head>
    <title>Apple IIe</title>
        <script type="text/javascript">
           function contents() {
          
          alert('contents');
            document.getElementById("main").innerHTML = '<div>HTML CUT FOR    UNDERSTANDING</div>' ; 
            document.body.onKeyUp = vcredits();
        }
        function vcredits() {
            alert('2');
        }
       </script>
    </head>
    <body onkeyup="contents()">
        <div id="main">
            <span id="loading">apple //e</span>
        </div>
    </body>
</html>
Raisdead is offline
View Public Profile
 
Old 10-06-2008, 08:47 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
Does anybody have any questions to help me solve this problem
Raisdead is offline
View Public Profile
 
Old 10-06-2008, 12:15 PM Re: Simple javascript; changing onkeypress (At least it sould be simple)
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,528
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Tried to get this to work, and it won't.

The basic problem is that you are changing the event that is still active, so it will trigger the new event instantly.
Even toggling the events by using the onkeyup event to change the onkeypress event still triggered the second event.

You will probably need to start playing about with time delays to set the functions.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?

Last edited by chrishirst; 10-07-2008 at 05:09 AM.. Reason: spellnig corrected
chrishirst is online now
View Public Profile Visit chrishirst's homepage!
 
Old 10-07-2008, 12:27 AM Re: Simple javascript; changing onkeypress (At least it sould be simple)
Average Talker

Posts: 29
Name: Taylor
Trades: 0
Thank you for your help... I thank your for all the time you put into it and effort you gave me... if you or anybody ever becomes inspired with a solution feel free to Pm me... Thanks
Raisdead is offline
View Public Profile
 
Closed Thread     « Reply to Simple javascript; changing onkeypress (At least it sould be simple)
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.63604 seconds with 12 queries