/    Sign up×
Community /Pin to ProfileBookmark

Help me plz it ‘s error (passing value to function when click link)

plz help me.
I found the error when i run it. For my propose, i want to sent values to function when click links and show a value that has sent into textbox. I had made two links for testing passing value to function but it didn’t work it don’t sent value to “loadToTextBox” function.
Please help me for solving this problem ~-_-~.

Thank in advance
From Aranyuth
//////////////////it don’t work, i want to do like this/////////////////////
<html>
<script language=”javascript”>
<!–
function loadToTextBox(code, bg_or_font) {
if(bg_or_font == “bg”) {
document.submitColor.bg_code.value = code;
}else{
document.submitColor.font_code.value = code;
}
}
//–>
</script>

//
<!–<body OnLoad=loadToTextBox(‘ff’)>–>
<body>
<form method=”post” action=”” name=”submitColor”>
<input type=”text” name=”bg_code”>
<input type=”text” name=”font_code”>
</form>

//first links for testing
<a href=”javascript:loadToTexBox(‘ff’, ‘bg’)”>000000</a>
//second links for testing
<a href=”choose_bg_font_color.html” OnClick=loadToTexBox(‘ff’, ‘bg’);”>000001</a>

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

//////////////////it it like this, it work why?? ///////////
// i’m confuse
<html>
<script language=”javascript”>
<!–
function loadToTextBox(code) {
document.submitColor.bg_code.value = code;
}
//–>
</script>

//
<body OnLoad=loadToTextBox(‘ff’)>
<form method=”post” action=”” name=”submitColor”>
<input type=”text” name=”bg_code”>
<input type=”text” name=”font_code”>
</form>

//first links for testing
<a href=”javascript:loadToTexBox(‘ff’, ‘bg’)”>000000</a>
//second links for testing
<a href=”choose_bg_font_color.html” OnClick=loadToTexBox(‘ff’, ‘bg’);”>000001</a>

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

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 23.2002 — [i]Originally posted by aranyuth [/i]

[B]<a href="javascript:loadToTexBox('ff', 'bg')">000000</a>[/b][/quote]


Shouldn't this be

[font=courier]<a href="javascript:loadToTex[b]t[/b]Box('ff', 'bg')">[/font]

[b]<a href="choose_bg_font_color.html" OnClick=loadToTexBox('ff', 'bg');">000001</a>[/b][/quote]

and this should be

[font=courier]<a href="choose_bg_font_color.html" OnClick=[b]"[/b]loadToTex[b]t[/b]Box('ff', 'bg');">[/font]

Also, this link will change your page and clobber all your variables, so the onClick won't do you any good even if you fix the syntax errors.
Copy linkTweet thisAlerts:
@aranyuthauthorNov 23.2002 — Thank you so much ?
×

Success!

Help @aranyuth 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,
)...