Adding a textfield and label onblur

I’m trying to add a text field when I focus off of the previous text field. I keep getting an

unterminated string literal on $("#props_"+i).after(" error. Is there an easier way to do this in yii using jui?

Here’s what I have:




	echo "<div id='props_$i' class='row'>";

	echo CHtml::textField("PropToPort[$i]", '', array('size'=>2, 'onblur'=>'js:

	if(typeof i == \'undefined\'){

		var i = '.$i++.';

	}else{

		i = i + 1;

	}

	var j = i++;

	$("#props_"+i).after("

		<div id=\'props_"+j+"\' class=\'row\'>

			<input type=\"text\" size=\"2\" name=\'PropToPort["+j+"]\' />

			

		<div>

	");'));

	echo CHtml::label('', "PropToPort[$i]", array('style'=>'display: inline;'));

	echo "<hr /></div>";



After I solve this issue I plan to do an ajax call to return the label of the newly generated text field as they type.

Hi,

you are using multiline javascript which breaks down javascript code.

read here:

http://www.electrictoolbox.com/javascript-multi-line-strings/

Your code should be created either with backslash [\] or via heredoc syntax <<< >>>, e.g.:




        echo "<div id='props_$i' class='row'>";

        echo CHtml::textField("PropToPort[$i]", '', array('size'=>2, 'onblur'=>'js:

        if(typeof i == \'undefined\'){

                var i = '.$i++.';

        }else{

                i = i + 1;

        }

        var j = i++;

        $("#props_"+i).after(" \

                <div id=\'props_"+j+"\' class=\'row\'> \

                        <input type=\"text\" size=\"2\" name=\'PropToPort["+j+"]\' /> \

                        \

                <div> \

        ");'));

        echo CHtml::label('', "PropToPort[$i]", array('style'=>'display: inline;'));

        echo "<hr /></div>";



Cheers

lubos