SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy HELP! Forms, lists/menus, validate.......

    I am by no means a javascript writer and desparately need help. Like days agoI have a form that I have validating, and it works fine but with one quirk. I have a drop down menu, with 7 choices, one of them is "other". If the "other" option is chosen, it is required to fill in the text box field named "other". Now that all works, but even after the text box field "other" is filled in, the alert message still pops up that 'the text box other needs to be filled', then submits the form after you hit okay. I'm sure it's just one more line of script, but I can't figure it out, it's probably something easy.... please help!
    This is the script:
    <SCRIPT>
    function validate() {
    if (Application.EighteenYOA.options[0].selected) {
    alert('Eighteen Years of Age, please choose Yes or No.');
    event.returnValue=false;}
    if (Application.LawsuitType.options[0].selected) {
    alert('Please select a Lawsuit Type.');
    event.returnValue=false;}
    if (Application.ObtainedFunding.options[0].selected) {
    alert('Obtained Funding, please choose Yes or No.');
    event.returnValue=false;}
    if (Application.ChangedAttorney.options[0].selected) {
    alert('Changed Attorney, please choose Yes or No.');
    event.returnValue=false;}
    if (Application.Bankruptcy.options[0].selected) {
    alert('Bankruptcy, please choose Yes or No.');
    event.returnValue=false;}
    if (Application.ReadDisclosure.options[0].selected) {
    alert('You must read the disclosures and choose yes.');
    event.returnValue=false;}
    if (Application.ContactAttorney.options[0].selected) {
    alert('Contact Attorney, please choose Yes or No.');
    event.returnValue=false;}
    if(Application.LawsuitType.options(7).selected) {
    alert('You must enter the other type of lawsuit.')
    event.returnValue=false;}
    }
    </SCRIPT>

    Probably need another line of script to tell it that if "LawsuitType.options(7).selected" and "other field is filled in" then returnValue=true, but not sure how to write that part of the code.
    PLEASE HELP and quick! Im beggin anyone!
    Thank you sooooooooo much!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    Code javascript:
    if (Application.LawsuitType.options[7].selected) {
        if (!Application.otherLawsuitType.value) {
            alert('You must enter the other type of lawsuit.');
            event.returnValue = false;
        }
    }
    Last edited by paul_wilkins; May 22, 2008 at 18:29.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the code....
    the site is www.lawsuitcashfunding.com/app2.html ---- this is the test site app page......
    I tried your code but it doesn't work.... it won't validate anything....I appreciate it alot though,

    let me explain a little more.....
    there is a drop down menu with 7 options with one option being 'other'
    only if they choose the 'other' option are they required to fill in the text field titled 'other'
    if they choose 'other' from the drop down menu and still enter the text in the field titled 'other' the alert message still pops up.... so i'm confused.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    4 Thread(s)
    First, your script is going to work only in IE and not in most other browsers, because IE is one of the very few browsers that automatically define script variabled for elements with named attributes.

    Add the following statement to the top of your script, and see this recent posting where someone else had that very problem solved.
    http://www.sitepoint.com/forums/showthread.php?t=549482

    Code javascript:
    var Application = document.getElementsByName('Application')[0];

    Now that that's out of the way, you need to change options(7) to options[7], if you haven't already, and then use the actual name of the options field, changing it in my example from otherLawsuitType to Other - then it will work.

    Code javascript:
    if (Application.LawsuitType.options[7].selected) {
        if (!Application.Other.value) {
            alert('You must enter the other type of lawsuit.');
            event.returnValue = false;
        }
    }
    Last edited by paul_wilkins; May 22, 2008 at 18:29.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    May 2008
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OMG! You are a genius! I needed to add another closing bracket too, because it didn't work the first time, but man you ROCK!
    Thank you, Thank you, Thank you, Thank you, Thank you, Thank you!
    Did I mention Thank you?
    You are a life saver! Again, I can't thank you enough!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •