form target & IE

L

Lethal Possum

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
 
E

Evertjan.

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';
}
}
 
L

Lethal Possum

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. said:
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';
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top