Disha Goyal
Disha Goyal

Reputation: 624

Incorrect string format

i need help in correcting this string.

I am trying:

$returnStr = 'Condition<select name="lstCondition" onchange="javascript:addDateTextbox(this.value,' . ' " ' . $colName . ' ", ' . $key . ')">'; 

I want this:

<select name="lstCondition" onchange="javascript:addDateTextbox(this.value, 'dateTime', 42)>

I am getting this:

 <select name="lstCondition" onchange="javascript:addDateTextbox(this.value, " dateTime ", 42)>

Upvotes: 0

Views: 107

Answers (3)

Parag
Parag

Reputation: 4812

try the below code

 <?php 
$returnStr = '<select name="lstCondition" onchange="javascript:addDateTextbox(this.value, \'dateTime\', 42)"><option>Select</option></select>';
echo $returnStr;
?>

Upvotes: 0

BugFinder
BugFinder

Reputation: 17858

In your statement

name="lstCondition" onchange="javascript:addDateTextbox(this.value,' . ' " ' . $colName  . ' ", ' . $key . ')">';

you have spaces each side of the ' marks hence you're getting the spaces round the colname. If you change it to

name="lstCondition" onchange="javascript:addDateTextbox(this.value,' . '\'' . $colName  . '\', ' . $key . ')">';

you should get the result you wanted. I have escaped the '

Upvotes: 2

Yan Berk
Yan Berk

Reputation: 14428

$returnStr = 'Condition<select name="lstCondition" 
              onchange="javascript:addDateTextbox 
             (this.value,' . ' \'' . $colName . ' \',' . $key . ')">';

Upvotes: 2

Related Questions