Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Coding problem with <input type=text

    I have had a problem reported by users over a period of three years. I'm sure everyone that sees it doesn't report it, but with 8,000 visitors a day it only gets reported about once every three months so it is very obscure. Computers/program errors are usually consistent so this confuses me.

    I have an <input box where users enter M or F to indicate their sex. If they don't do it correctly, they get an alert message. The problem is that they swear they have entered M or F but still get the message.

    Now today for the first time a user tells me the <input box contains: onChange='parent.create.setSex(this)'

    Here is all the relevant code:

    function setSex(a){Sx=a.value;
    if (Sx!="m" && Sx!="M" && Sx!="f" && Sx!="F"){alert("Please enter M or F to indicate your Sex.")}
    if (Sx=="m"){Sx="M"; parent.image.document.f1.sx.value="M"}
    if (Sx=="f"){Sx="F"; parent.image.document.f1.sx.value="F"}

    // Sex box
    c+="<tr><td align=center class='formfields'>";
    c+="Sex:&nbsp;";
    c+="<input type=text name=sx value="+Sx+" onChange='parent.create.setSex(this)' ";
    c+="size=1 maxlength=1 class='formfields' border=1>";
    c+="&nbsp;&nbsp;&nbsp;&nbsp;";

    // Age box
    c+="Age:&nbsp;";
    c+="<input type=text name=ag value="+Ag+" onChange='parent.create.setAg(this)' ";
    c+="size=3 maxlength=4 class='formfields' border=1>";
    c+="&nbsp;&nbsp;&nbsp;&nbsp;";

    Note that the age box is coded similarly but it has never caused a problem.

    Up until a week ago I used & where you now see &&. I posted here and learned the difference but evidently it wasn't the problem.

    Thanks for any ideas, Peter

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    478
    Thanks
    0
    Thanked 51 Times in 50 Posts
    Could you post the URL to this form?

    Simplify it a little? Assume they enter the correct data and process that first. If Sx=='m' AND Sx=='f' both fail, then it alerts, not before.
    Code:
    Sx=a.value.toLowerCase();
    if(Sx == "m") {Sx="M"; parent.image.document.f1.sx.value="M"}
    else if (Sx == "f") {Sx="F"; parent.image.document.f1.sx.value="F"}
    else {alert("Please enter M or F to indicate your Sex.")}

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Kansas, USA
    Posts
    478
    Thanks
    0
    Thanked 51 Times in 50 Posts
    Or, since the majority of the time the answer is going to be one or the other, use a radio group?

    Code:
    M <input type="radio" name="sex" value="m">
    F <input type="radio" name="sex" value="f">
    
    function setSex(r){
    if(r[0].checked) parent.image.document.f1.sx.value=r[0].value;
    else if(r[1].checked) parent.image.document.f1.sx.value=r[1].value;
    else alert("Please check M or F to indicate your Sex.");
    }

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the replies.

    First, your simplified code does look better. I'm self-taught at this and it doesn't come easy.

    Second, the radio buttons really do make sense. I think when I coded it a few years ago I just wanted to use text boxes for all input for consistency. Actually, I think I'll just make it a drop down menu.

    That will certainly eliminate the problem, though I will remain curious how it could happen so irregularly.

    FYI my webpage is http://www.caloriesperhour.com/index_burn.html


  •  

    Posting Permissions

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