JS Prompt and Insertion

He has: 1,380 posts

Joined: Feb 2002

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

&lt;script type="text/javascript" language="Javascript"&gt;<!--//--><![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]')
}
//--><!]]>&lt;/script&gt;
'

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's picture

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*

Smiling

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's picture

She has: 5,507 posts

Joined: Feb 2000

The semi-colon terminator is optional. Smiling

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Suzanne wrote: The semi-colon terminator is optional. Smiling

Yes, that is what I'm lamenting. Sad It makes scripts easier to read, following C/Java syntax better. Kids these days... Wink

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 Wink

Abhishek Reddy's picture

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:")){
'

Smiling

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.