Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Stupid Javascript/HTML


chess_rock's Avatar
Member
0 0

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
 

ghost's Avatar
0 0

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.


chess_rock's Avatar
Member
0 0

it didn't work… :( tried that one already :(


ghost's Avatar
0 0

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.


chess_rock's Avatar
Member
0 0

THANK YOU!!!! :D:D:D:D:D:D:D:D I spent a huge time looking and now i feel completely idiot for not seeing the not closed tag at the end…

thank you very much :)

chess_rock's mind is saying silently: "chess_rock…you're stupid chess_rock…it was only a stupid tag!!!aaaaaaah!"

lmao:p


ghost's Avatar
0 0

[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.


chess_rock's Avatar
Member
0 0

sorry for the double post…. this is a good lesson since the mistake might be a very tiny and stupid thing…

second…. Admin can close and delete this thread! ;)


ghost's Avatar
0 0

M4zh4r wrote: <script> tag is not closed properly.

That's what I get for quoting without syntax-checking. Good catch.


ghost's Avatar
0 0

Take Pwnall's advice. It'll help to use firebug in such cases.


chess_rock's Avatar
Member
0 0

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's Avatar
Member
0 0

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


ghost's Avatar
0 0

Firebug is available with latest release of mozilla firefox 3.0.2.


ghost's Avatar
0 0

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.


ghost's Avatar
0 0

Firebug is only necessary when you have dynamically-generated HTML in a page. The Error Console should show you script errors just fine. Other than that… make it a habit to glance over your code before you publish it. Opening and closing tags is a fundamental concept that you need to grasp quickly.


ghost's Avatar
0 0

Zephyr, is it common or even acceptable in professional web programming to use:

&lt;? ?&gt;
&lt;% %&gt;
&lt;script type=&quot;text/php&quot;&gt;&lt;/script&gt;

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.


ghost's Avatar
0 0

In general, you'll only see <?php and ?> surrounding PHP code (except when the shorthand <?=$variable?> is being used). The <script> tags are generally just used for Javascript (or VBScript, too, I suppose).


chess_rock's Avatar
Member
0 0

It seems that the expression:

markup&lt;? ?&gt;

is becoming quite popular when talking about that…it is an abbreviation which might soon replace the old and common:

markup&lt;?php ?&gt;

a simplification of the language…


yours31f's Avatar
Retired
10 0

I've also noticed it becoming more and more popular, but I don't see it as a bad thing, I mean it's the only language to have the <? in it that I know of so <?PHP would be unnecessary unless there is another. Anyways, Glad you found your mistake.


fashizzlepop's Avatar
Member
0 0

Nobody said it was a bad thing…


sam207's Avatar
Member
0 0

I think <% %> will work if u change php.ini settings.. Also <?php ?> is the default one.. & u can use <? ?> but u can disable or enable this short style in php.ini settings.. & that <script> should also work..


chess_rock's Avatar
Member
0 0

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?


ghost's Avatar
0 0

chess_rock wrote: 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? Syntax differences and, if there's not a rewrite rule in effect, the file extensions.


fashizzlepop's Avatar
Member
0 0

The server usually looks at the extension to see how to parse/compile it. It doesn't just look at the "<? ?>" vs "<?php ?>" for example. Only would a web browser need that kind of identification difference.


ghost's Avatar
0 0

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.