Jump to content

Some Help Please...


Luke4123

Recommended Posts

Well I have started off learning some PHP forms. In the one I made, you have to input your Name and Favourite Color. Is there anyway that when the input there favourite color, the background or the font turns that color?eg.Name: LukeFavourite Color: RedThen the background or the font would turn red?Thanks in advance

Link to comment
Share on other sites

  • Replies 100
  • Created
  • Last Reply

Do you want it to happen immediately or after they've submitted the form?If immediately, you'll need to alter the style through javascript.If after, then the return page will have to use PHP to open the data file you're saving stuff in, find the color, assign it to a variable, and then embed that variable in a CSS declaration.All very doable stuff.One caution: since color names are only sorta standardized in CSS, you might want to get color information through a select element instead of text element. You can look up a bunch of valid color names and make them the options in the select element. OR make up your own color names for the options' text and assign appropriate color numbers to the options' values.

Link to comment
Share on other sites

If you mean immediately, then thats not PHP, thats Javascript that would do that. If you want for PHP to save the favorite color, and then read it back, you could either do it using an IF in the PHP file, or using cookies/javascript to set it using the style elements supported in most newer browsers.

Link to comment
Share on other sites

Have a look at this page:http://www.w3schools.com/html/html_colornames.aspThere are some colour names that are recognised by some browsers and you can change the font or background by using the name egprint "<p style='color: {$_POST['colorInput']}'>THIS TEXT IS IN A NICE {$_POST['colorInput']} COLOUR</p>";(Where $_POST['colorInput'] fetches the colour typed into the form.)But if the name of the colour isn't supported then you'll have to find another way - maybe Switch...Case or create an array storing the colour names and the hex RGB values. Why not create a drop down list on the form input page so that it is limited to the colours you want them to choose?Would only work after they clicked a submit button, to do it otherwise you're looking at javascript as mentioned above.

Link to comment
Share on other sites

Yeah I want it so as soon as they click Submit, its changes color.eg.Welcome Luke.Your favourite color is *Red*And make the color Red, be red. Is that JS?

Link to comment
Share on other sites

So how would I do that with JavaScript? The If...Else Statement?

Link to comment
Share on other sites

You would catch the submit action of the form. E.g.

<script type="text/javascript">function changestyle(form) {	var name = form.name.value;	var color = form.color.value;	document.getElementById("output").innerHTML = "Welcome " + name + "<br />Your favourate colour is <span style=\"color:" + color + "\">" + color + "</span>";	return false;}</script><!-- ... --><form onsubmit="return changestyle(this)">Name: <input type="text" name="name" /><br />Color: <input type="text" name="color" /><br /><input type="submit" value="Submit" /></form><div id="output">Please enter the fields above</div>

Link to comment
Share on other sites

Wow! Awesome. Thanks for that. Where abouts did you learn JS?

Link to comment
Share on other sites

Wow! Awesome. Thanks for that. Where abouts did you learn JS?
Em... look around. We're at W3Schools, remember?
Link to comment
Share on other sites

Where abouts did you learn JS?
I already knew C, so it looked very familiar to me. I originally learned by imitating scripts from sites that did interesting things. I still recommend that method--if you can find a script to read that's at your level, or just above your level, and if you can be pretty sure it is standards-compliant and doesn't use a lot of old-fashioned routines. You don't want to copy someone's bad habits.
Link to comment
Share on other sites

I already knew C, so it looked very familiar to me. I originally learned by imitating scripts from sites that did interesting things. I still recommend that method--if you can find a script to read that's at your level, or just above your level, and if you can be pretty sure it is standards-compliant and doesn't use a lot of old-fashioned routines. You don't want to copy someone's bad habits.
So do you suggest I learn C first?
Link to comment
Share on other sites

not really. Deidre's Dad probably only learned C because he was in a class or something along those lines. Just so happened that when he started working with Javascript, since it's C based it made a bit more sense. same thing happened with me and C++. Just learning the basic syntax for C++ increased my understanding of Javascript and PHP immensily(sp?). Personally i think you learning one of the other languages first would depend entirely on how keen you are to Javascript. Some questions i would ask myself if i were you would be 1. If i'm given a script, any script, in javascript, can i understand at least 99% of it?2. Can I take a script given to me, and edit it so long as i know all of the things that are going on in the script?3. Am i really ready for a language that is more strict than most of the ones i'm used to seeing (I know C++ can be really annoying, not so sure about C)If you answered yes to all 3 of those questions, go ahead and pick of the C++ for dummies book. I personally love that guy's sense of humor. It assumes you know nothing about C++ or programming in general, and makes fun of programmers in the nerdiest possible ways. "People who work with computers like to make really cool acronyms for everything that does something cool, but that could be made confusing for people who aren't in the field of computers. Take for instance the term OOP. Personally, sounds like i just did something wrong. But iti actually means Object Oriented Programming." Just a small paraphrase from the book since i don't have it on me at the moment.If not, just download free scripts off of hotscripts and edit them, comment things out line by line to see what happens without that specific piece. It helped me a lot before i learned C++ and PHP.

Link to comment
Share on other sites

The most important thing for me when I learn a language is that , Why I need to learn ?If you plan to learn the language and then not use it , then is waste of time for me .I research all things what come on my mind with language .And then I see is it useful to me or not , the people can said is it not useful or is it useful . But there words does not write my code .You need to think with your head what you will learn and why do you need . How to test it ?example with this . If you see that wall is black and all other people said that is green , if you think with your head you will said that is black.And for them you will be a mad man , because you think with your head . Where is the purpose of life when you live a some other guy life ?

Link to comment
Share on other sites

Thanks guys for your replies. :mellow: I mainly want to learn JavaScript because its interactive for the person who is viewing the site, like entering there name and stuff in a Form. :) BTW Can a Moderator change from PHP to JavaScript. Thanks muchly. :)

Link to comment
Share on other sites

I already knew C, so it looked very familiar to me. I originally learned by imitating scripts from sites that did interesting things. I still recommend that method--if you can find a script to read that's at your level, or just above your level, and if you can be pretty sure it is standards-compliant and doesn't use a lot of old-fashioned routines. You don't want to copy someone's bad habits.
Yeah I found reading through some PHP helped me understand JavaScript. Like with the functions it made it easier to understand. :)
Link to comment
Share on other sites

There are some programming concepts that you absolutely need to know and understand to the point where you can explain them to other people or use them without needing a reference. It doesn't matter which language, the concepts apply to all languages. These concepts include things like variables, constants, data types, operators, control structures like loops and decision structures, and functions. If you need to use a reference to see how to define a function or constant or how to use a for loop then you need to study more or get more experience, those types of things should be second nature if you're going to do any serious programming. Later on you can branch out into things like classes to make your programs more efficient, but you really need to understand the basics. It doesn't matter how you do it as long as you do it. A language like C is a good language for learning because: 1) it is very small, it only consists of the basic concepts. You have to learn them to write C. Anything you do with regard to input/output, file operations, etc is handled by prebuilt functions inside the Standard I/O library, but the actual language is very small and concise.2) it is a more strongly typed language then PHP and Javascript, you are required to have an understanding of data types if you're writing a C program. If you define a variable as an integer variable then you can't assign a string to it, it's only an int. Other languages might not be as strongly typed, but you still need a solid understanding of what data types are and how to manage them.C is pretty easy to learn, at least as easy as PHP. The most difficult thing with C is setting up your environment, installing the compiler and libraries and things like that, sort of like with PHP where you need to install the interpreter and extensions and a web server. But yeah, if you can write and compile a C program that does something as simple as reading whatever you type and writing it into a file, then you're well on your way to understanding what you need to understand to use PHP or any other language.

Link to comment
Share on other sites

C is pretty easy to learn, at least as easy as PHP. The most difficult thing with C is setting up your environment, installing the compiler and libraries and things like that, sort of like with PHP where you need to install the interpreter and extensions and a web server.
That's exactly the reason I started with PHP like most true newbies here. While it's hard to install PHP on your PC the first time, there are free hosts with PHP. And that's how my very first experiments with PHP were (we're talking "hello world!" here). It was pretty straightforward to see or not to see a result, without much hassle in installing and keeping things on my computer. Oh, the times... there was a saying... something like "blessed are the unaware" that describes how I felt back then (you know the "WOW!" factor when you do something new).
Link to comment
Share on other sites

That's how I was with C in college. We had a Unix network where we could compile and run everything, and it was pretty cool to write my C programs and then watch them compile and run. It was also fun trying to crash the network, like putting a fork statement in an infinite loop and watching the core dump. One time in particular when we were learning about forking processes and signal handling and things like that we had to write a program that forked itself (clone itself into a new process, so the one program becomes two independent running processes) and then you could type something into one of the processes and the other process could respond to it. That was pretty cool to see, and the code to do something like that is pretty small and relatively easy to understand.

Link to comment
Share on other sites

I got my first C compiler in 1988. I learned Basic back in High School on an old DEC whose only I/O was a flipping teletype machine! Programs were stored on long strips of yellow paper; if it got torn, you fixed it with Scotch tape. Anyway, in the late 80s I'd fooled around with GW-Basic on my first PC and was frustrated by it's limitations. C++ existed, I now know, but I'd heard that most Microsoft stuff, including DOS, were written in C, so that made it my choice. I'm pretty sure I could not have wrapped my head around OOP at the time.We had the debate about learning C before or after Javascript already, so I don't want to go there. All I really meant was that C has had a profound influence on the look and feel of many languages developed after it. And because of this, when you know C to begin with, you come to Javascript or Perl or PHP and start writing useful programs pretty quickly.But, as JSG suggests, the learning curve for programming itself is pretty steep. Visualizing how dozens of separate functions will work together takes practice and discipline. Just giving variables useful names is an art in itself. (I think the old DEC could only use 1-2 characters. Yecch!) Anyway, except for memory management and a few other niceties they don't have to deal with, javascript and PHP are pretty rich languages. You can certainly master the big principles with either of them, and learning one should make learning the other lots easier.I confess I do like javascript's object-oriented routines. object.sort(param) feels more natural somehow than sort(object, param). Maybe it's me.

Link to comment
Share on other sites

Some more help:I need some more help and thought I would just post it in here instead of making a whole new thread.Well here is my PHP form:

<html><body><form action="post.php" method="post">Name:<br /><input type="text" name="name" /><br />Post: <br /><input type="text" name="post" /><input type="submit" /></form></body></html>

and the other one aswell:

<html><body><b><?php echo $_POST["name"]; ?> says:<br /></b><?php echo $_POST["post"]; ?><br /></body></html>

And on my website, I want to make a comment section. ATM if you do it, the comment appears there, but isnt permantly saved on the site for people to see. How do I do that?

Link to comment
Share on other sites

You need a database. Instead of printing the information from $_POST, you save it in a database. When you pull up the comments page then you get everything out of the database and display each comment. Have you looked into databases yet?

Link to comment
Share on other sites

For something really simple like that you could also just output to a file. But it is a good idea to learn how to interact with a database through PHP :)

Link to comment
Share on other sites

So the most simple way to do it with PHP is with a database? Are they pretty easy? :) Or how do you OutPut a file?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.


×
×
  • Create New...