/    Sign up×
Community /Pin to ProfileBookmark

similar thing to "vB Code"

I am trying to make a JS Script that does similar stuff to the vBCode in forums. I have problems with adding it in to the text box. It says the txt is undefined.

I tried more things like it:

document.forms.txt
document.all.txt

but it gives the same error everywhere. This is my code:

[code=php]
<!– CODE FUNCTION –>
<script>
<!–
function code(tag){

if (tag = “b”) {
document.forms.txt.value = document.forms.txt.value & “<b></b>”;
}
if (tag = “a”) {
//Not changed yet
//txt.text = txt.text & “<a href=””></a>”;
}
………….
}
–>
</script>
<!– END CODE FUNCTION –>
[/code]

Also, can you use ” in JS and HTML too?

How do I get to the text box?
Is it different with text boxes that have multiple lines? I use it with one with 1 line and it works simply.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Bootsman123Dec 22.2003 — [code=php]
<html>
<head>
<script language="javascript">
<!--
function code (tag)
{
if (tag == "b")
{
document.forms.txt.value = '<b></b>';
}
}
//-->
</script>
</head>
<body>
<form name="forms">
<input type="text" name="txt">
</form>
<a href="javascript:code ('b');">Bold</a>
</body>
</html>
[/code]


This should do it, although it's untested.
Copy linkTweet thisAlerts:
@aoeguyauthorDec 24.2003 — Wouldnt it replace the whole thing?
Copy linkTweet thisAlerts:
@Bootsman123Dec 25.2003 — I understand it now.

document.forms.txt.value = document.forms.txt.value + '<b></b>';

This should work.
Copy linkTweet thisAlerts:
@aoeguyauthorDec 25.2003 — So it was just that it had to be type=JS and single quotes then?

Thanks boot
×

Success!

Help @aoeguy 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...