Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 The Prompt Command.
Index -> Graphics and Design, Web Design -> (X)HTML Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
fear01




PostPosted: Wed Jan 18, 2006 5:10 pm   Post subject: The Prompt Command.

Sorry for posting again, but this question is really bugging me and is the only thing standing in my way of my work. I was wondering how I could use the prompt command to change the color of the text.

I get the user's name and prompt them again for a color, but whenever the color is input it will either be black or another color that was previously done before. Basically it only works half the time and I want to know how to change this. (Ex. What is your name? ____. What color text do you want? ____. = NAME but wrong or no color.)
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Wed Jan 18, 2006 5:31 pm   Post subject: (No subject)

I'm confused as to what this has to do with xhtml, unless you are doing this for a webpage...
fear01




PostPosted: Wed Jan 18, 2006 5:46 pm   Post subject: (No subject)

I am! I am! Come back!
md




PostPosted: Wed Jan 18, 2006 6:17 pm   Post subject: (No subject)

do you have a link to this page? It's hard to help debug things when I've got no idea how you are doing something
fear01




PostPosted: Wed Jan 18, 2006 6:30 pm   Post subject: (No subject)

I don't know how to do the code thing, so i just pated it.


<HTML>

<HEAD>
<title></title>
<META NAME="author" CONTENT="">
</HEAD>

<body>
<body bgcolor="red">

<script language="JavaScript">
var user_name;
var userpic;
user_name = prompt("What is your name?", "");
user_pic1 = prompt("What text color would you like?", "");

document.write("
Welcome ", user_name, " to the world of JavaScript"

);
</script>

</body>

</html>

I have been doing this for a week and stuck on how to change the font color. Go ahead and laugh at my lame skills, but I'll get better, then conquer the world...
md




PostPosted: Wed Jan 18, 2006 6:57 pm   Post subject: (No subject)

First, I'll rewite your stuff using xhtml instead of HTML which is on it's way out. Second, you might want to read about CSS, as it's what you probably want to be using.

code:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN'
   'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
    <title>You should really have a title! ;)</title>
    <meta name="author" content="cornflake">
</head>

<body>
<body style='background-color: RGB(255,0,0)'>
 
    <script language="JavaScript">
        var user_name;
        var userpic; 
        user_name = prompt("What is your name?", ""); 
        user_pic1 = prompt("What text color would you like?", "");
        if(user_pic1 == "red")
            rgb_color = "RGB(255,0,0)"
        if(user_pic1 == "green")
            rgb_color = "RGB(0,255,0)"
        if(user_pic1 == "blue")
            rgb_color = "RGB(0,0,255)"
        else
            rgb_color = "RGB(0,0,0)"
 
        document.write("<span style='text-align: center; color: ", rgb_color, "'>Welcome ", user_name, ", to the world of JavaScript.</span>");

    </script>

</body>

</html>

note that you'll have to add to the color code for any other colors you want.

It seems that there is some resistance to using xhtml and CSS here on compsci, but it is a much nicer standard then HTML; and aside from IE (which soon might get support for much of CSS) it's a widly used standard. Plus it makes things so much nicer Razz You can use the w3c validator (http://validator.w3.org) to check to see if your page is valid. IT tells you pretty specifically what you need to fix if it isn't.
fear01




PostPosted: Wed Jan 18, 2006 7:10 pm   Post subject: (No subject)

I see, I see. But is there anyway to put the variable for color into some sort of script that changes it to the color desired. Or am I going to have to put in the general colors for it to work? By the way, thank you for your help, it has been most appriciated.
md




PostPosted: Wed Jan 18, 2006 7:49 pm   Post subject: (No subject)

you could write a function, but in the end I think you'll end up with a big list of if statements somewhere.
Sponsor
Sponsor
Sponsor
sponsor
fear01




PostPosted: Wed Jan 18, 2006 8:12 pm   Post subject: (No subject)

Ah fudge...
Display posts from previous:   
   Index -> Graphics and Design, Web Design -> (X)HTML Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: