|
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?
irt.org | Knowledge Base | JavaScript | Form | Q1708 [ previous next ]
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?
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>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.