...

View Full Version : JavaScript Help Needed



bgner
03-18-2012, 09:04 PM
new to JavaScript, simple question...

question: how do i determine an output from a prompt to be bold?

e.g. a user enters "hello" and the output printed from the prompt becomes bold


one=parseFloat(prompt('enter number',0.bold));

DanInMa
03-18-2012, 09:14 PM
how are you outputting "one"?

example:


document.write("<strong>"+one+"</strong>")

VIPStephan
03-18-2012, 09:18 PM
Note that document.write is useful for quick demonstration but should not be used in real life (best practice and stuff, you know).

Old Pedant
03-19-2012, 02:24 AM
I think both Dan and VIP *may* have missed what you are trying to do:


one=parseFloat(prompt('enter number',0.bold));

I am assuming that you mean you want the default value of the number (the number 0) to be shown in the prompt in bold.

The JavaScript prompt( ) function can *NOT* be controlled in any way. There is no way to ask that text be bold or italic or to change the font or font size.

If you want to do something like this, you'll have to create your own pseudo-prompt code by popping up a window or by using a popon <div>.

Even if I'm wrong about you wanting the default value of the prompt to be shown in bold--even if you want what is entered to the prompt to be shown in bold as Dan demonostrated--I think you are making a mistake in using prompt() in the first place. In general, the prompt( ) function should never be used in real world coding. It's pretty much just a beginner's (or debugger's) tool.

webdev1958
03-19-2012, 06:53 AM
Note that document.write is useful for quick demonstration but should not be used in real life (best practice and stuff, you know).

What's wrong with using it to write to child pages? :thumbsup:

If you don't use document.write(), what are you using to write content or javascript variables' values to child pages?

webdev1958
03-19-2012, 07:00 AM
question: how do i determine an output from a prompt to be bold?

e.g. a user enters "hello" and the output printed from the prompt becomes bold

You could set css font-weight of the output html container to bold.

Old Pedant
03-19-2012, 07:09 AM
What's wrong with using it to write to child pages? :thumbsup:

If you don't use document.write(), what are you using to write content or javascript variables' values to child pages?

Oh, heck, I know I've certainly created child pages using document.write before.

But even for child pages, where possible I'd much prefer to load in an HTML (or server-created!) page and then use DOM methods to change the contents. I can't think of many situations where that wouldn't work better than document.write. Some, yes. But not many.

webdev1958
03-19-2012, 07:23 AM
...Some, yes. But not many.

Agree :) In threads where this issue comes up I always advise against using document.write() for writing to the current page except in KISS type tutorials/demo code. And I then go on to say I have no issue with using it to write to child pages where appropriate. So if someone tells me to not use it at all in "real life", I personally see that as garbage advice.

bgner
03-20-2012, 01:55 AM
thanks for all the feedback i managed to solve the problem by using

a=(prompt("enter word:",0));
document.write("word entered: <b><i> " + a + "</b></i></br>");

giving the word entered in bold e.g. word



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum