javascript - Modal dialog box does not communicate with main HTA window -
i have javascript in hta looks this:
var result = null; window.showmodaldialog("dialog.hta", window, "dialogheight:300px; dialogwidth:300px"); alert(result);
dialog.hta:
<html> <head> <title>dialog box</title> <meta http-equiv="msthemecompatible" content="yes"/> </head> <body style="background:#f0f0f0"> <select id="colors"> <option selected>red</option> <option>blue</option> <option>green</option> <option>yellow</option> </select><br/> <script type="text/javascript"> function ok(){ window.dialogarguments.result = colors.getelementsbytagname("option")[colors.selectedindex].innerhtml; window.close(); } </script> <button onclick="ok()">ok</button> <button onclick="window.close()">cancel</button> </body> </html>
the problem when press ok alert(result)
in main hta window says null, when click on ok button in modal dialog box. how can says option user selects in list when ok button pressed , null when cancel button pressed?
this how modal dialog works:
in main app:
// call dialog, , store returned value variable var result = showmodaldialog(path, argument, options);
on dialog close:
// set returnvalue var elem = document.getelementbyid("colors"); window.returnvalue = elem[elem.selectedindex].text; top.close();
after setting returnvalue
in dialog, can read result
after dialog has been closed.
option
elements didn't have innerhtml
in old ies, hence you've use text
property instead. can add value
attribute select
element, , create return value in simple way:
window.returnvalue = document.getelementbyid('colors').value;
Comments
Post a Comment