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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Syntax Question: What are the +'s for?

    I have been using this code for years to allow a user to enter a number of hours (varialbe Hr) and minutes (Mn). Every few months a single user will report that the <input> box for minutes contains:

    onChange='parent.create.setMn(this)'

    and they can't get rid of it. In looking at the coding I am wondering if instead of value="+Mn+" I should use single quotes: value='+Mn+'

    Perhaps their browser is getting confused by the double quotes within double quotes?

    But it's been so long since I coded it I no longer remember what the plus signs on either side of the variable Mn are for. I want to understand the code again before I go changing things.

    c+="Time:&nbsp;";
    c+="<input type=text name=hr value="+Hr+" onChange='parent.create.setHr(this)' ";
    c+="size=2 maxlength=2 class='textBox' border=1>Hour";
    c+="<input type=text name=mn value="+Mn+" onChange='parent.create.setMn(this)' ";
    c+="size=2 maxlength=2 class='textBox' border=1>Minutes";

    I'd also appreciate your looking over the code.

    Thanks, Peter

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Because you didn't enclose the attribute values in double quotes and if Mn is empty, the value of the textbox becomes the onChange handler. This would be the output:
    Code:
    <input type=text name=mn value= onChange='parent.create.setMn(this)' size=2 maxlength=2 class='textBox' border=1>Minutes
    You should always put double quotes in attribute values. Use single quotes in Javascript string literal to make it less confusing.
    Code:
    c+='Time:&nbsp;';
    c+='<input type="text" name="hr" value="'+Hr+'" onchange="parent.create.setHr(this)" ';
    c+='size="2" maxlength="2" class="textBox" border="1">Hour';
    c+='<input type="text" name="mn" value="'+Mn+"' onchange="parent.create.setMn(this)" ';
    c+='size="2" maxlength="2" class="textBox" border="1">Minutes';
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Vancouver, WA
    Posts
    233
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It always seemed to work with out the quotes (I guess it wasn't!) so I figured I could just leave them out.

    Thanks, Peter


  •  

    Posting Permissions

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