JS Prompt and Insertion
Ok...two problems here in building my own CMS:
#1- I am trying to have buttons that when clicked, open a JS prompt. This JS prompt doesnt' appear. I have the following in my section
<script type="text/javascript" language="Javascript"><!--//--><![CDATA[//><!--
function bold(loc) {
var b = window.prompt("What text do you want to make bold?")
document.GetElementById(loc).write('[bold]' && b && '[/bold]')
}
function underline(loc) {
var u = window.prompt("What text do you want to underline?")
document.GetElementById(loc).write('[underline]' && u && '[/underline]')
}
function italics(loc) {
var i = window.prompt("What text do you want to italicize?")
document.GetElementById(loc).write('[italics]' && i && '[/italics]')
}
function link(loc) {
if (var text = window.prompt("Link Text or Name:")){
var url = window.prompt("Link Location or URL:")}
document.GetElementById(loc).write('[link=' && url && ']' && text && '[/link]')
}
//--><!]]></script>
and the links as:
<a href="javascript:link()" alt="[Link]"><img src="/img/link.gif" width="20" height="20" alt="[Link]" /></a>
#2- As you can see, I'm trying to write the text with tags to be interpreted later...but how do you write to the I-beam position in the text box/area (the flashing vertical line)? Right now I am just using ".write" but I'm pretty sure that will overwrite....I left the "loc" value of the functions open, just so I can build it in later...
Thanks
Abhishek Reddy posted this at 04:37 — 4th August 2004.
He has: 3,348 posts
Joined: Jul 2001
- getElementById, not GetElementById.
- the JS concat operator is +, not &&. && is the logical AND operator.
- whatever happened to the whole semicolon line terminator thing? *sigh*
kb posted this at 13:39 — 4th August 2004.
He has: 1,380 posts
Joined: Feb 2002
I thought that was needed, but I searched around google, and it seemed optional (all the tutorial sites didnt use them)
Thanks...I'll check it out and repost
Suzanne posted this at 14:20 — 4th August 2004.
She has: 5,507 posts
Joined: Feb 2000
The semi-colon terminator is optional.
Abhishek Reddy posted this at 22:20 — 4th August 2004.
He has: 3,348 posts
Joined: Jul 2001
Yes, that is what I'm lamenting. It makes scripts easier to read, following C/Java syntax better. Kids these days...
kb posted this at 03:29 — 8th August 2004.
He has: 1,380 posts
Joined: Feb 2002
OK, I made those changes...but I can't get the JS prompt window to even appear...you can check this out at (still under visual development)
terrifictots.com/update
Don't worry...you can't update the content... it's not working yet
Abhishek Reddy posted this at 09:44 — 8th August 2004.
He has: 3,348 posts
Joined: Jul 2001
Line 67? Change:
if (var text = window.prompt("Link Text or Name:")){
to:
if (text = window.prompt("Link Text or Name:")){
kb posted this at 15:10 — 8th August 2004.
He has: 1,380 posts
Joined: Feb 2002
Awesome, now the windows work...but the same question applies:
How do i insert text into a textarea or textbox where the cursor is? You know what I'm talking about?
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.