Hello!
I believe I want to achieve the same thing like Brian, BUT I’m following a very different approach. The plugin code is
global $content;
$e = &$modx->Event;
if (($e->name == 'OnDocFormRender') && ($content['template'] == 14)) {
$output = "<!-- tv2docvar Plugin -->\n";
$output .= "<script type=\"text/javascript\">\n";
$output .= "function tv2docvar_set(){\r\n" .
" var source = document.getElementById(\"tvVAStart\");\r\n" .
" var sourceval = source.value; // date and time\r\n" .
" var destination = document.getElementById(\"tvVAEnde\");\r\n" .
" if(destination.value == \"\"){ // do not overwrite existing input\r\n" .
" alert('sourceval=' + sourceval);\r\n" .
" destination.value = sourceval;\r\n" .
" alert('destination.value=' + destination.value);\r\n" .
" }\r\n" .
"}\r\n" .
"var myform = document.getElementsByName(\"mutate\")[0];\r\n" .
"myform.addEventListener(\"submit\", tv2docvar_set, false);\r\n" .
"</script>";
$output .= "<!-- end tv2docvar Plugin -->\n";
$e->output($output);
}
This plugin inserts javascript when using the given Template. My template is for storing events with start end end date/time. On submission, the plugin gets the input start date and -- if there is no end date given -- sets the end date equal to the start date.
At least, this is what the plugin is supposed to do. But it does not. As you can see, I have inserted two "alerts" for debugging. In both outputs, I get the correct values. This means: my JS has got the input start date, sets the form field value of end date, reads it for verification and outputs the correct end date wich is now equal to the start date.
This is, when I use Firefox 3.0.10. If I use Internet Explorer 7, the alerts are not output.
But, the big problem is: The actual TV is not really set to the given start date. If I reopen the same page for editing, the end date is still empty. In both Fx and IE.
What can be the problem here?
Any ideas very much appreciated.
Thanks in advance
Martin