www.webdeveloper.com
Results 1 to 7 of 7

Thread: Javascript Prompt Text Color Choices?

Hybrid View

  1. #1
    Join Date
    Aug 2008
    Posts
    31

    Javascript Prompt Text Color Choices?

    Hello.

    what i need is, if someone hits ok on a javascript input box, then their inputed text comes out normal. but if they hit cancel, their inputed text should come out blue.

    heres my code:

    Code:
    <script type="text/javascript">
    function firstName() {
    var name = prompt ("Please Enter Your Name");
    alert('Some Text');
    document.getElementById("1").innerHTML = name;
    document.getElementById("2").innerHTML = name;
    document.getElementById("3").innerHTML = name;
    document.getElementById("4").innerHTML = name;
    document.getElementById("5").innerHTML = name;
    document.getElementById("6").innerHTML = name;
    document.getElementById("7").innerHTML = name;
    document.getElementById("8").innerHTML = name;
    document.getElementById("9").innerHTML = name;
    document.getElementById("10").innerHTML = name;
    document.getElementById("11").innerHTML = name;
    }
    </script>
    im sure id use and if else statement but im not entirely sure how this can be done. any help would be appreciated, thanks.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,666
    Given this:

    var name = prompt ("Please Enter Your Name");

    If the user clicks the [Cancel] button, then all you're going to get back, in the name variable, is a null value. Period.

  3. #3
    Join Date
    Aug 2008
    Posts
    31
    ok well what if i changed the alert to confirm and had the choices there? could i do it then?

  4. #4
    Join Date
    Feb 2008
    Posts
    1,666
    Confirm offers no possibility for input. But if you combined both prompt followed by confirm, then you would have your two choices.

  5. #5
    Join Date
    Aug 2008
    Posts
    31
    yea thats what i meant, sorry. how do i do that?

  6. #6
    Join Date
    Feb 2008
    Posts
    1,666
    OK, both names and ids are supposed to start with a letter. So...
    HTML Code:
    <script type="text/javascript">
    function firstName() {
        var obj = document.getElementById("D1");
        var name = prompt("Please Enter Your Name");
        if (comfirm(name)) {
            obj.innerHTML = name;
        } else {
            obj.innerHTML = name;
            obj.style.color = 'blue';
        }
    }
    </script>

  7. #7
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    That of course assumes that your visitor doesn't check the disable JavaScript checkbox at the bottom of the prompt or confirm dialog so as to kill the rest of the script (assuming that they are using a browser that always offers that option in all the dialogs to make using them for testing easier).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles