I have a form loading on a page that loads with an onclick event on the parent page using the following javascript. It gets loaded in a DIV.
function loadContent(elementSelector, sourceURL) {
$(""+elementSelector+"").load("http://myurl.co.nz/"+sourceURL+"");
}
Then on another on click event (within the new form) one of the fields in the form is开发者_如何学运维 populated with a random password.
<label>Password:</label><input type="text" name="password" /><br/>
<input type="button" value="Generate Password" onClick="genPwd()"/>
function genPwd(){
$.post("rpc.php", {
method: "genPwd"
},
function(data,textstatus){
document.form.password.value = data.message;
}, "json");
}
All the javascript on the page is included at load time.
Chrome and FF are fine with this but IE8 says that document.form.password does not exist, I assume because it is not in the original page. Any way around this?
Cheers
AFAIK document.form
is deprecated. You could use this cross browser solution instead:
$('#passwordFieldId').val(data.message);
精彩评论