By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,249 Members | 1,647 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,249 IT Pros & Developers. It's quick & easy.

form target & IE

P: n/a
Hi all,

I'm trying to make the following script work on Internet Explorer:

function choose_target(form) {
if (form.popup.checked == true) {
form.target = '_blank';
} else {
form.target = '_self';
}
return true;
}

This works fine in Firefox but IE says the form object has no target
property! I thought the target property was pretty standard? Is there
something I don't get here?

Thanks in advance for your help.

Thomas

Feb 23 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lethal Possum wrote on 23 feb 2006 in comp.lang.javascript:
I'm trying to make the following script work on Internet Explorer:

function choose_target(form) {
if (form.popup.checked == true) {
form.target = '_blank';
} else {
form.target = '_self';
}
return true;
}

This works fine in Firefox but IE says the form object has no target
property! I thought the target property was pretty standard? Is there
something I don't get here?


This works fine in IE6:

==========================
<form target='zzz'
onsubmit=
'this.target="_blank";alert(this.target);return false;'>
<input type=submit>
</form>
==========================

'form' is a reserved word, not to be used as a variable!

Try:

<form onsubmit='choose_target(this)'>

and:

function choose_target(theForm) {
if (theForm.elements['popup'].checked)
theForm.target = '_blank';
else
theForm.target = '_self';
}

or:

function choose_target(theForm) {
theForm.target =
(theForm.elements['popup'].checked)
? '_blank'
: '_self';
}

or:

function choose_target(theForm) {
with (theForm) {
target =
(elements['popup'].checked)
? '_blank'
: '_self';
}
}
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 23 '06 #2

P: n/a
Thank you,

You led me to my actual shameful mistake: I have an input field in my
form that is named target!

All the best,

Thomas

Evertjan. wrote:
Lethal Possum wrote on 23 feb 2006 in comp.lang.javascript:
I'm trying to make the following script work on Internet Explorer:

function choose_target(form) {
if (form.popup.checked == true) {
form.target = '_blank';
} else {
form.target = '_self';
}
return true;
}

This works fine in Firefox but IE says the form object has no target
property! I thought the target property was pretty standard? Is there
something I don't get here?


This works fine in IE6:

==========================
<form target='zzz'
onsubmit=
'this.target="_blank";alert(this.target);return false;'>
<input type=submit>
</form>
==========================

'form' is a reserved word, not to be used as a variable!

Try:

<form onsubmit='choose_target(this)'>

and:

function choose_target(theForm) {
if (theForm.elements['popup'].checked)
theForm.target = '_blank';
else
theForm.target = '_self';
}

or:

function choose_target(theForm) {
theForm.target =
(theForm.elements['popup'].checked)
? '_blank'
: '_self';
}

or:

function choose_target(theForm) {
with (theForm) {
target =
(elements['popup'].checked)
? '_blank'
: '_self';
}
}
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Feb 23 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.