Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1708 How can I pass the value of a hidden field into a confirm dialog box when the submit button is pressed, so I can ask the user if they really want to edit/remove the visible version of the hidden value?

You are here: irt.org | FAQ | JavaScript | Form | Q1708 [ previous next ]

Try:

<html>

<head>

<script language="JavaScript"><!--
function validate() {
  if (document.myForm.hidden.value != document.myForm.visible.value)
    return confirm('Is this the correct value: ' + document.myForm.visible.value);
  return true;
}
//--></script>

</head>

<body>

<form name="myForm" onSubmit="validate()">
<input type="hidden" name="hidden" value="Hello world">
<input type="text" name="visible" value="Hello world">
<input type="submit" value="Submit">
</form>

<script language="JavaScript"><!--
// reset visible form field in case user pages back to this page
document.myForm.visible.value = document.myForm.hidden.value;
//--></script>

</body>

</html>

©2018 Martin Webb