Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am tring to display the title of the page in my form.
Currently, I can do this with javascript and display the title in other places on the page, but not in the form. I am posting the simple code to help understand what I am saying.
--------------------
<head>
</head>
<body><SCRIPT LANGUAGE="JavaScript">
document.write(document.title)
</script>
<form>
<input type="text" value=javascript:document.write(document.title) />
</form></body>
</html>
------------------
You can see from the code, that I am displaying the variable on the page.Then I am tring to display the variable in a FORM. It doesn't work in the form becuase I don't know the syntax for displaying a variable in a form.
Any help is greatly appreciated.

You might be better off storing the value of document.title in a variable, then printing the value with document.write(). For instance:
var docTitle = document.title;
document.write(<form> ... + docTitle + ... </form>);Doing this might be considered trivial, however it would make your script more readable. Here is a more elegant solution to your problem:
<body>
<script>
document.write("<form><input type = 'text' value = '" + document.title + "'/></form>");
</script>
</body>Give that a try. I hope this helps you on your HTML project. Good luck.
- Rolos

Here is an easy solution. Put a Javascript block at the end of the page (or at least after the field to be populated) and update the value instead of trying to populate it within the tag itself.
Example:
<script>
document.forms[0].fieldName.value = document.title;
</script>fieldName needs to be the name of the form field you are populating.
forms[0] can be replaced with the name you gave the form. If you have more than 1 form on the page you will need to either use the form name or the correct form itteration in the brackets.
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |