...

View Full Version : Syntax Question: What are the +'s for?



peterinwa
04-14-2007, 08:54 PM
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

glenngv
04-14-2007, 10:06 PM
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:

<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.

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';

peterinwa
04-14-2007, 10:30 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum