Forum Moderators: open

Message Too Old, No Replies

Syntax Question: What are the +'s for?

         

peterinwa

7:56 pm on Apr 14, 2007 (gmt 0)

10+ Year Member



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

Dabrowski

7:59 pm on Apr 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nothing wrong with the code.

In JS you use + to concat strings, the same as adding numbers it adds strings together.

c+="<input type=text name=hr value="+Hr+" onChange='parent.create.setHr(this)' ";

This means variable called 'c' that already contains "Foo Bar!" (for example) will then contain "Foo Bar!<input type=text name=hr value=(value of Hr here) onChange='parent.create.setHr(this)' " and the rest of the INPUT box is appended on the next line.

Can't see any reason at all that a user would have an incorrect value setting, but I always single quote html parameters, so you could try changing to "type='text' name='hr'" etc....

I know it shouldn't make a difference, but on the odd occasion it might.