form target & IE

Discussion in 'Javascript' started by Lethal Possum, Feb 23, 2006.

  1. 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
     
    Lethal Possum, Feb 23, 2006
    #1
    1. Advertising

  2. Lethal Possum

    Evertjan. Guest

    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)
     
    Evertjan., Feb 23, 2006
    #2
    1. Advertising

  3. 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)
     
    Lethal Possum, Feb 23, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan

    Web Form Target

    Dan, Oct 18, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    483
    Steve C. Orr [MVP, MCSD]
    Oct 18, 2003
  2. Federico Bari
    Replies:
    2
    Views:
    1,979
    Federico Bari
    Aug 31, 2003
  3. Federico Bari

    IFRAME AS FORM TARGET! POSSIBLE?

    Federico Bari, Sep 2, 2003, in forum: HTML
    Replies:
    4
    Views:
    32,752
    Federico Bari
    Sep 2, 2003
  4. TheKeith
    Replies:
    9
    Views:
    1,184
    Leif K-Brooks
    Oct 22, 2003
  5. mohit
    Replies:
    0
    Views:
    602
    mohit
    Jan 23, 2008
Loading...

Share This Page