Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JavaScript Help Needed

    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));

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    how are you outputting "one"?

    example:

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

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,479
    Thanks
    6
    Thanked 981 Times in 954 Posts
    Note that document.write is useful for quick demonstration but should not be used in real life (best practice and stuff, you know).

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I think both Dan and VIP *may* have missed what you are trying to do:
    Code:
    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.
    Last edited by Old Pedant; 03-19-2012 at 02:28 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by VIPStephan View Post
    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?

    If you don't use document.write(), what are you using to write content or javascript variables' values to child pages?
    Last edited by webdev1958; 03-19-2012 at 07:00 AM.

  • #6
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by bgner View Post
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Quote Originally Posted by webdev1958 View Post
    What's wrong with using it to write to child pages?

    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    Quote Originally Posted by Old Pedant View Post
    ...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.

  • #9
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •