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.

PHP Forum


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



Freelance Jobs

Reply
trying to do monster text in fight with attack button and iframe
Old 07-28-2010, 02:13 PM trying to do monster text in fight with attack button and iframe
Webmaster Talker

Posts: 611
Trades: 0
Hi, I have an iframe at the top and bottom of the page. An an image of a monster in the middle. I tried to press attack in the bottom iframe, and have it output the battle messages in the top iframe. Basically, I have an interface where I dont want the whole page to reload just to output the messages. Is there any solution to this, or even some javascript code snippets? Any help greatly appreciated. So far the button just brings up a new page that it points to in the iframe, which doesn't really do me any good. Thanks. Derek
silverglade is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-28-2010, 02:26 PM Re: trying to do monster text in fight with attack button and iframe
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
You really need to be using Java applets/servlets for such a scenario or have the whole thing written in Flash as Dragonfable do
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-28-2010, 02:55 PM Re: trying to do monster text in fight with attack button and iframe
Webmaster Talker

Posts: 611
Trades: 0
Thanks very much Chris. Do you know if I can output php variables with javascript. Like I tried to do below? It doesn't work.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Untitled Document</title>
    </head>
    <body>
    <?php $battleText="you hit for 100 points!";?>
        <div id="container">
            This is the default text
        </div>
        <form><input type="submit" id="link" value="change"/></form>
        <script type="text/javascript">
            var a = document.getElementById('link');
            a.onclick = function(){
                var d = document.getElementById('container');
                var def = d.childNodes[0].nodeValue;
                t = 5000;
                setTimeout(function(){
                    d.childNodes[0].nodeValue = <?php echo $battleText; ?>
                    setTimeout(function(){
                        d.childNodes[0].nodeValue = "Newer Text";
                        setTimeout(function(){
                            d.childNodes[0].nodeValue = def;
                        }, t);
                    }, t);
                }, t);
            }
        </script>
    </body>
</html>
silverglade is offline
Reply With Quote
View Public Profile
 
Old 07-28-2010, 03:50 PM Re: trying to do monster text in fight with attack button and iframe
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
nodeValue is a XML DOM method, so will only work as you expect when reading or setting values of an XML document NOT a HTML document.

In a HTML document it is not only the elements that are "nodes", so you may NOT be setting the correct node.

secondly this
Code:
d.childNodes[0].nodeValue = <?php echo $battleText; ?>
Is NOT going to work ESPECIALLY if the $battleText contains spaces

You will need to wrap it in single quotes so it becomes a string

d.childNodes[0].nodeValue ='<?php echo $battleText;?>';
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-28-2010, 03:55 PM Re: trying to do monster text in fight with attack button and iframe
Webmaster Talker

Posts: 611
Trades: 0
Is there a way I could add a button to do this code that updates a iframe with variable text?
Any more help greatly appreciated. Thank you. Derek

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css">
body {
background-color: black;
color: gold;
}


</style>

</head>
<body>
<html>
<body>

<script type="text/javascript">
var my_var = "Hello World!"
    

function text2add(){
return  '<font color=gold><strong>'+my_var+'</strong></font>';
}
</script>
<form> 
<form><input type="submit"  value="change" onClick="text2add();"/></form>
Main page! Frame below.

<br><br>

<iframe src="iframe.html" ></iframe>

</body>
</html> 
</body>
</html>
silverglade is offline
Reply With Quote
View Public Profile
 
Old 07-28-2010, 04:05 PM Re: trying to do monster text in fight with attack button and iframe
Webmaster Talker

Posts: 611
Trades: 0
and this are the contents of my iframe page

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<script type="text/javascript">
 document.write(parent.text2add());
 
</script>

This is my iframe 
</body>
</html>
silverglade is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to trying to do monster text in fight with attack button and iframe
 

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 0.22599 seconds with 12 queries