Forum Moderators: open
works fine.
I've got a form with a hidden field like so:
<input type="hidden" name="linktitle" value="HELP"></form>
How can I get my JS to execute in the value part (where it says HELP)? I've tried numerous methods and none have worked. Any ideas? Thanks!
document.formtwo.linktitle.value = 'document.title';
formtwo is the name of the form, linktitle is the name of the hidden field. However, the returned value is then document.title and not the actual title... I tried it without quotes and got nothing. I also tried:
document.write(document.formtwo.linktitle.value+document.title);
an it returned nothing. What am I missing?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> This is my title </title>
</head>
<body><form name="myForm">
<input type="hidden" name="linktitle" value="HELP" />
</form><script>
document.myForm.linktitle.value = document.title;
alert(document.myForm.linktitle.value);
</script></body>
</html>
2. If you're still going to use JavaScript, you need to wait for the window to finish loading, as the document.title might not be available until the DOM is ready.
Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset:utf-8">
<title>This is my title</title>
</head>
<body>
<form name="myForm">
<div>
<input type="hidden" id="linktitle" name="linktitle" value="" />
</div>
</form>
<script type="text/javascript">
window.onload = function() {
document.getElementById('linktitle').value = document.title;
};
</script>
</body>
</html>