Why doesn't this simple HTML code work?, I don't know HTML, and this code I was given doesn't work... |
Why doesn't this simple HTML code work?, I don't know HTML, and this code I was given doesn't work... |
Marz Fisch |
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! |
CharlesEF |
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."); |
Christian J |
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. |
CharlesEF |
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 |
|
Frederiek |
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 . |
Lo-Fi Version | Time is now: 26th April 2024 - 11:54 PM |