Stupid Javascript/HTML
Hello there people… I've been studying and programming a webpage the whole day, and i'm completely tired… Before i go to sleep i typed the following code:
<body>
<form id="welcome">
<input type="text" id="hello">
<input type="button" id="save" value="ok" onclick="display()">
</form>
<script type="text/javascript">
var name = document.welcome.hello.value
function display()
{
alert("Hello, " + name)
}
<script>
</body>
</html>```
All i want it to do is to show me the name you type in the box.
There is a mistake in this, but i can't find it... :( My eyes hurt me too much now, and i can't go to sleep before figuring out what is the goddamn mistake. Can anyone please help me out here please? chess_rockie needs to sleep :P lol
Zephyr_Pure wrote: [quote]chess_rock wrote: <form name="welcome"> <input type="text" name="hello"> <input type="button" id="save" value="ok" onclick="display()"> </form>
<script type="text/javascript"> function display() { alert("Hello, " + document.welcome.hello.value); } <script>
Try that.[/quote]
<script> tag is not closed properly.
[edit]Well, it's already been resolved. One thing I do see that is that the <script></script> code is normally placed in the <head></head> tags. Another is to end your statements with semicolons. Look into the FF add on Firebug. It allows you to view errors in HTML. It also allows you to edit other web sites (local changes until you refresh) coding so it is very useful for learning.
Pwnzall wrote: Try and see if you have Javascript enabled on your browser. Do you have Firefox? If so, look into an addon called Firebug. It will let you debug coding errors in your HTML. One thing I do see that is that the <script></script> code is normally placed in the <head></head> tags. Another is to end your statements with semicolons.
thanks man… the thing is that i missed the "/" at the end for lack of attention… i'm using notepad++ and sometimes i miss some of firebug's features like correction.
about the head tags… this is only one code i'll work more tomorrow… i'll change it to be added to the cookies for people that login to be greeted.
and the semi colons… i was used to put them, but now, most browsers and progs don't require semi colons at the end, so i've stopped putting them. i'm what they call…lazy xP hehe
chess_rock wrote: [quote]M4zh4r wrote: Take Pwnall's advice. It'll help to use firebug in such cases.
hehe… i will :) the thing is that i had firebug, and then, when i upgraded firefox from 2.0 to 3.0, firebug was not compatible, and i didn't reinstall it. I'll look for it again :D[/quote]
I installed FF 3.0.1 in it's own folder so that I was able to keep both, you could try that as well. However, you can not run both at the same time and my AV got "uppity" when I tried to rename the executable to do so. I just checked, and indeed there is an update for Firebug compatible with FF3 as of 9/12.
Zephyr, is it common or even acceptable in professional web programming to use:
<? ?>
<% %>
<script type="text/php"></script>
I've adhered to the tags insisted upon by reputable sites, but I've seen these variants in codes I've studied on the web. How often do you review code at your job and stumble upon this?
Hopefully, I will be able to land a summer job as a PHP programmer/web designer when I turn 16, and I would like to know what to expect coming from someone in the field.
well, had to revive this thread discussion… I was taking a look in W3 tutorials about languages i didn't know anything about, and i realized that ASP language makes use of the symbols: <? ?>…
now comes the question… since php is really living this "simplification era", how can a computer identify if what is being written is ASP or PHP? anyone knows?
Nice catch… my pre-coffee post originally saw the question as being human perception, not server perception. Regardless, whether just habit or not, I find it easier to read the code when the tags are used as such:
<?php ?> = PHP <? ?> = PHP shorthand <% %> = ASP <script></script> = Javascript
While they may all be used with PHP at any given time, we really have to ask how much of an optimization we'd gain from using the alternatives to <?php ?>… as opposed to retaining the readability of various code.