SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,563
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why this function is not working?

    Here is a small function, and I'm not finding why it's not working ...

    PHP Code:
    function setEmploi() {
        var 
    emp document.ededfil.jeune1.value;
        var 
    emp2 document.ededfil.jeune2.value;
            if ((
    emp=="My value")&&(emp2=="")) {
                
    window.alert("Your forgot to fill up the second value"); document.ededfil.jeune2.focus();
                return 
    false;
            }
        } 
    Any help? Thanks.

    PS. Later, I'm calling the function with the submit button > onSubmit="return setEmploi()"

    Note: var emp is taking a radio button value.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't return anything unless an error occurs. Try adding return true; after the if-statement.

    Also, your method for looking up the values may not work in non-IE browsers, which do not tend to pollute the global namespace with the names of every form element on the page.

    Use id="jeune1" etc. on your form control, and use
    Code:
    var emp = document.getElementById("jeune1").value;
    to retrieve the value.
    Birnam wood is come to Dunsinane

  3. #3
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,563
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Tommy. I'll give it a try.


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
  •