The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Why doesn't this simple HTML code work?, I don't know HTML, and this code I was given doesn't work...
Marz Fisch
post Jan 1 2016, 05:31 PM
Post #1





Group: Members
Posts: 1
Joined: 1-January 16
Member No.: 23,870



Here is the code:

<html>
<head>
Input desired protein form here: <!-- This will change the wording above the text box -->
<br>
</br>
<div id='main'>
<form onsubmit="return redirect()">
<input id="search_form_input" type="number" name="query" />
kg/m^2 <!-- This will change the wording next to the text box -->
<input type="submit" value="Calculate" />
</form>
</div>
<script type="text/javascript">
function redirect()
{
var query = document.getElementById('search_form_input').value;
if (query != '') {
// The variables below are fine, but the numbers can change
var grubs = (query * 1.585600625459897);
var tub = (query * 22198.417954378219279);
var grubtub = (query * 0.015085853568801);
document.write(You will need approximately " + grubs + "kg of waste to
feed approximately " + tub + " grubs. You will need " + grubtub + " m^2 area for your grub
tub.);
}
return false;
}
</script>
"Be sure to hit refresh in order to input new calculations" <!-- This will change the wording
below the text box -->
</head>
</html>

I would greatly appreciate any help!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jan 2 2016, 02:23 AM
Post #2


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



What is supposed to happen? 'It doesn't work' doesn't tell us much. I see several errors on this 1 line:
CODE
document.write(You will need approximately " + grubs + "kg of waste to feed approximately " + tub + " rubs. You will need " + grubtub + " m^2 area for your grub tub.);

That line should be:
CODE
document.write("You will need approximately " + grubs + "kg of waste to feed approximately " + tub + " grubs. You will need " + grubtub + " m^2 area for your grub tub.");
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Jan 2 2016, 07:59 AM
Post #3


.
********

Group: WDG Moderators
Posts: 9,661
Joined: 10-August 06
Member No.: 7



Also, form elements belong in the page's BODY section (not in HEAD).

Finally, document.write will print a new page with the result. If you want them on the same page as the form, use innerHTML instead.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post Jan 2 2016, 10:33 AM
Post #4


Programming Fanatic
********

Group: Members
Posts: 1,981
Joined: 27-April 13
From: Edinburg, Texas
Member No.: 19,088



QUOTE(Christian J @ Jan 2 2016, 06:59 AM) *

Also, form elements belong in the page's BODY section (not in HEAD).

Good catch, I didn't notice that.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Jan 2 2016, 11:56 AM
Post #5


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



And, the following is missing:
- DOCTYPE
- TITLE tag inside the HEAD tag (required)
- BODY tags, in which to put the DIV and FORM elements

See also http://htmlhelp.com/reference/html40/structure.html .
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th April 2024 - 11:54 PM