/    Sign up×
Community /Pin to ProfileBookmark

Just a simple question

I wanna write some script; but something just doesn’t work. I’ll try to be as short as possible;

[CODE]
[COLOR=”Navy”]<html>[/COLOR]
[COLOR=”navy”]<head>[/COLOR]
[COLOR=”Magenta”]<style[/COLOR] [COLOR=”Sienna”]type=[/COLOR][COLOR=”Blue”]”text/css”[/COLOR][COLOR=”magenta”]>[/COLOR]
[COLOR=”magenta”]iframe.iFrmMain[/COLOR]
[COLOR=”magenta”]{[/COLOR]
display[COLOR=”Magenta”]:[/COLOR] [COLOR=”Blue”]none[/COLOR][COLOR=”magenta”];[/COLOR]
[COLOR=”magenta”]}[/COLOR]
[COLOR=”Magenta”]</style>[/COLOR]

[COLOR=”Red”]<script[/COLOR] [COLOR=”Sienna”]language=[/COLOR][COLOR=”Blue”]”javascript”[/COLOR] [COLOR=”Sienna”]type=[/COLOR][COLOR=”Blue”]”text/javascript”[/COLOR][COLOR=”red”]>[/COLOR]
[B]var[/B] txt [COLOR=”Blue”]= ‘click <a href=”#” onclick=”LnkClicked();”>here</a>’ [/COLOR] ;

[B]function[/B] LnkClicked[B][COLOR=”Navy”]() {[/COLOR][/B]
[COLOR=”DarkRed”]document.[/COLOR]getElementById([COLOR=”Blue”]’iFMain'[/COLOR]).style.display [COLOR=”blue”]= ‘block'[/COLOR] ;
[COLOR=”darkred”]document.[/COLOR]getElementById([COLOR=”blue”]’iFMain'[/COLOR]).src [COLOR=”blue”]= ‘http://www.google.com'[/COLOR] ;
txt [COLOR=”blue”]= ‘welcome to Google'[/COLOR] ;
[B][COLOR=”navy”]}[/COLOR][/B]
[COLOR=”red”]</script>[/COLOR]
[COLOR=”navy”]</head>[/COLOR]

[COLOR=”navy”]<body>[/COLOR]

[COLOR=”Magenta”]<center>[/COLOR]
[COLOR=”Navy”]<p>[/COLOR][COLOR=”Red”]<script>[/COLOR][COLOR=”DarkRed”]document.[/COLOR][COLOR=”Olive”]write[/COLOR][B][COLOR=”Navy”]([/COLOR][/B]txt[B][COLOR=”navy”])[/COLOR][/B];[COLOR=”Red”]</script>[/COLOR][COLOR=”Navy”]</p>[/COLOR]
[COLOR=”navy”]<p><iframe id=[/COLOR][COLOR=”Blue”]”iFMain”[/COLOR] [COLOR=”Navy”]class=[/COLOR][COLOR=”blue”]”iFrmMain”[/COLOR] [COLOR=”navy”]width=[/COLOR][COLOR=”blue”]”902″[/COLOR] [COLOR=”navy”]height=[/COLOR][COLOR=”blue”]”450″[/COLOR]>[COLOR=”navy”]</iframe></p>[/COLOR]
[COLOR=”Magenta”]</center>[/COLOR]

[COLOR=”navy”]</body>[/COLOR]
[COLOR=”navy”]</html>[/COLOR]
[/CODE]

‘txt’-variable changes its value but what to do to change the text referenced to ‘txt’-variable in document body too?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ATommyauthorJan 16.2009 — [CODE]
...
[COLOR="Red"]<script[/COLOR] [COLOR="Sienna"]language=[/COLOR][COLOR="Blue"]"javascript"[/COLOR] [COLOR="Sienna"]type=[/COLOR][COLOR="Blue"]"text/javascript"[/COLOR][COLOR="red"]>[/COLOR]
[B]var[/B] txt [COLOR="Blue"]= 'click <a href="#" onclick="LnkClicked(txt);">here</a>' [/COLOR] ;

[B]function[/B] LnkClicked[B][COLOR="Navy"]([/COLOR]txt[COLOR="Navy"])[/COLOR] {[/B]
[COLOR="DarkRed"]document.[/COLOR]getElementById([COLOR="Blue"]'iFMain'[/COLOR]).style.display [COLOR="blue"]= 'block'[/COLOR] ;
[COLOR="darkred"]document.[/COLOR]getElementById([COLOR="blue"]'iFMain'[/COLOR]).src [COLOR="blue"]= 'http://www.google.com'[/COLOR] ;
[B]return[/B] [COLOR="blue"] 'welcome to Google'[/COLOR] ;
[B][COLOR="navy"]}[/COLOR][/B]
[COLOR="red"]</script>[/COLOR]
...
[/CODE]
Copy linkTweet thisAlerts:
@FangJan 16.2009 — &lt;html&gt;
&lt;head&gt;
&lt;style type="text/css"&gt;
iframe.iFrmMain
{
display: none;
}
&lt;/style&gt;

&lt;script language="javascript" type="text/javascript"&gt;
var txt = 'click &lt;a href="#" onclick="LnkClicked(this);"&gt;here&lt;/a&gt;' ;

function LnkClicked(obj) {
document.getElementById('iFMain').style.display = 'block' ;
document.getElementById('iFMain').src = 'http://www.google.com' ;
obj.previousSibling.nodeValue = 'welcome to Google ' ;
}
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;center&gt;
&lt;p&gt;&lt;script&gt;document.write(txt);&lt;/script&gt;&lt;/p&gt;
&lt;p&gt;&lt;iframe id="iFMain" class="iFrmMain" width="902" height="450"&gt;&lt;/iframe&gt;&lt;/p&gt;
&lt;/center&gt;

&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@ATommyauthorJan 16.2009 — <i>
</i>...
var txt = 'click &lt;a href="#" onclick="LnkClicked([COLOR="Red"]this[/COLOR]);"&gt;here&lt;/a&gt;' ;

function LnkClicked([COLOR="red"]obj[/COLOR]) {
document.getElementById('iFMain').style.display = 'block' ;
document.getElementById('iFMain').src = 'http://www.google.com' ;
[COLOR="red"]obj.previousSibling.nodeValue = 'welcome to Google ' ;[/COLOR]
}
...
[/QUOTE]


But now I have "Welcome to Google here" instead of "Welcome to Google" ?
Copy linkTweet thisAlerts:
@ATommyauthorJan 16.2009 — [CODE]
<html>
<head>
<style type="text/css">
iframe.iFrmMain
{
display: none;
}
</style>

<script language="javascript" type="text/javascript">
[COLOR="red"] function pLoad() {
document.getElementById('pInnerTxt').innerHTML = 'click <a href="#" onclick="LnkClicked();">here</a>'
}[/COLOR]

function LnkClicked() {
document.getElementById('iFMain').style.display = 'block' ;
document.getElementById('iFMain').src = 'http://www.google.com' ;
[COLOR="red"] document.getElementById('pInnerTxt').innerHTML = 'welcome to Google ' ;[/COLOR]
}
</script>
</head>

<body [COLOR="red"]onLoad="pLoad();"[/COLOR]>

<center>
<p [COLOR="red"]id="pInnerTxt"[/COLOR]></p>
<p><iframe id="iFMain" class="iFrmMain" width="902" height="450"></iframe></p>
</center>

</body>
</html>
[/CODE]
×

Success!

Help @ATommy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...