Form trap problem

Discussion in 'Javascript' started by Garry Jones, Oct 5, 2006.

  1. Garry Jones

    Garry Jones Guest

    I want to ensure the users choose an item from a drop down list.
    The preselected value is "Not Chosen"

    Using script I cloned this from other working code, but it is broken
    somewhere.

    function checkform ( form )
    {
    if (form.ctsz.value == "Not Chosen") {
    alert( "Choose Size or choose opt out" );
    form.ctsz.focus();
    return false ;
    }
    return true ;
    }

    Any help appreciated.

    Garry Jones
    Sweden
     
    Garry Jones, Oct 5, 2006
    #1
    1. Advertising

  2. Garry Jones

    McKirahan Guest

    "Garry Jones" <> wrote in message
    news:eg3op4$lf9$...
    > I want to ensure the users choose an item from a drop down list.
    > The preselected value is "Not Chosen"
    >
    > Using script I cloned this from other working code, but it is broken
    > somewhere.
    >
    > function checkform ( form )
    > {
    > if (form.ctsz.value == "Not Chosen") {
    > alert( "Choose Size or choose opt out" );
    > form.ctsz.focus();
    > return false ;
    > }
    > return true ;
    > }
    >
    > Any help appreciated.


    "broken somewhere" is not very helpful to us.

    What does your form look like? Does it ihave:
    <form onsubmit="checkForm(this)" ...>
    and
    <select name="ctsz" ...>
    and
    <input type="submit" ...>

    Try using the Firefox browser to debug JavaScript.
    http://www.getfirefox.com
     
    McKirahan, Oct 5, 2006
    #2
    1. Advertising

  3. Garry Jones

    RobG Guest

    McKirahan wrote:
    > "Garry Jones" <> wrote in message
    > news:eg3op4$lf9$...
    > > I want to ensure the users choose an item from a drop down list.
    > > The preselected value is "Not Chosen"
    > >
    > > Using script I cloned this from other working code, but it is broken
    > > somewhere.
    > >
    > > function checkform ( form )
    > > {
    > > if (form.ctsz.value == "Not Chosen") {
    > > alert( "Choose Size or choose opt out" );
    > > form.ctsz.focus();
    > > return false ;
    > > }
    > > return true ;
    > > }
    > >
    > > Any help appreciated.

    >
    > "broken somewhere" is not very helpful to us.
    >
    > What does your form look like? Does it ihave:
    > <form onsubmit="checkForm(this)" ...>


    That would need to be:

    <form onsubmit="return checkForm(this)" ...>


    --
    Rob
     
    RobG, Oct 5, 2006
    #3
  4. Garry Jones

    McKirahan Guest

    "RobG" <> wrote in message
    news:...
    > > What does your form look like? Does it ihave:
    > > <form onsubmit="checkForm(this)" ...>

    >
    > That would need to be:
    >
    > <form onsubmit="return checkForm(this)" ...>


    Good catch.
     
    McKirahan, Oct 5, 2006
    #4
  5. Garry Jones

    Garry Jones Guest

    > "broken somewhere" is not very helpful to us.

    I have the checkform parameter and all values declared.

    I have been using a java code script to test for an empty field.

    This line of code results in the alert being triggered if the value is not
    entered

    if (form.deltport.value == "")

    I have only ever tested for empty fields and assumed thought I could adapt
    that code to test for a value.

    I want to test for the value of an option from a "select" control.

    Following the above example it should follow that this line of code

    if (form.ctsz.value == "Not Chosen")

    ..... triggers an alert if the value is Not Chosen - but it does not work-

    Greatful for any help in this matter.

    Garry Jones
    Sweden
     
    Garry Jones, Oct 6, 2006
    #5
  6. Garry Jones

    Garry Jones Guest

    "Garry Jones" <> skrev i meddelandet
    news:eg55ve$14b$...

    > if (form.ctsz.value == "Not Chosen")


    Sorry, I have been stupid (again).

    I should not have tested for the text of the select control but the value
    submitted by the option.

    Now working, sorry to have wasted your time.

    Garry Jones
    Sweden
     
    Garry Jones, Oct 6, 2006
    #6
    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. TCook
    Replies:
    0
    Views:
    369
    TCook
    Aug 13, 2006
  2. deepak nayak

    problem with IOT/Abort Trap

    deepak nayak, Dec 9, 2006, in forum: C++
    Replies:
    2
    Views:
    4,522
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=
    Dec 9, 2006
  3. gerotica

    Trap Int21h problem

    gerotica, Mar 24, 2007, in forum: C Programming
    Replies:
    4
    Views:
    327
    Jack Klein
    Mar 24, 2007
  4. jaspal singh

    trap keypress and keydown event in asp.net mobile form

    jaspal singh, Nov 24, 2006, in forum: ASP .Net Mobile
    Replies:
    1
    Views:
    1,458
  5. TCook
    Replies:
    0
    Views:
    171
    TCook
    Aug 13, 2006
Loading...

Share This Page