Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   form target & IE (http://www.velocityreviews.com/forums/t923186-form-target-and-ie.html)

Lethal Possum 02-23-2006 03:35 PM

form target & IE
 
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


Evertjan. 02-23-2006 03:59 PM

Re: form target & IE
 
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)

Lethal Possum 02-23-2006 05:47 PM

Re: form target & IE
 
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)




All times are GMT. The time now is 04:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.