Page 1 of 1

'onfocus' won't work inside dynamic generated <input> line

Posted: Mon Jan 30, 2012 6:20 pm
by pizzipie
I am generating a table to be used as a revision form. One <input> line contains: onfocus='showDisplayName(x,y)'. The purpose of this is to produce a standardized input of 'last_name, first_name'. This works fine in a regular HTML form context, but does not work in the dynamically created form. I would appreciate any help in making this work. Thanks in advance, RP.

Generated Table Output:
reviseTbl.png

Generated HTML Code:
generatedHTML.png
My Source Code:

Code: Select all

foreach($connectData as $key => $value) {
$k[]=$key;
$v[]=$value;
		
	if($key=='Name_ID') {
		continue;
	};
		printf("<td><label for='%s'>%s</label></td>\n",strtolower($key), preg_replace("/_/"," ",$key));
		
		if($key=="Display_Name") {
			
           printf("<td><input type='text' name='%s' onfocus='showDisplayName($v[1], $v[2]);' 
           		id='%s' value='%s'></input></td></tr>\n", strtolower($key), strtolower($key), $value);
			continue;
		};		
				
		if (contains($key, "Notes")) {
			printf("<td><textarea name='%s' id='%s'  rows=5 cols=81> '%s' </textarea></td></tr>\n",strtolower($key),
			 strtolower($key), $value);
			continue;
		};
	
		printf("<td><input type='text' name='%s' id='%s' value='%s'></input></td></tr>\n", strtolower($key), strtolower($key), $value);
		
	}; // if key	
	
printf("</table></form></fieldset></div>\n");

Re: 'onfocus' won't work inside dynamic generated <input> li

Posted: Tue Jan 31, 2012 6:22 am
by social_experiment

Code: Select all

onfocus="showDisplayName(Frank & Doady, Paddon3256);"
Probably the & that is causing the script not to work, if you use & instead, does it work?

Re: 'onfocus' won't work inside dynamic generated <input> li

Posted: Tue Jan 31, 2012 6:35 am
by Celauran
Could also be that the string arguments to your JS function aren't enclosed in quotes.

Re: 'onfocus' won't work inside dynamic generated <input> li

Posted: Tue Jan 31, 2012 1:38 pm
by pizzipie
Thank you, social_experiment and Celauram,

I tried the suggestions you each gave but no-go. I input names that didn't contain & and I also tried to quote the variables to showDisplayName().

I'll continue to experiment.

Again thanks to you both,

RP

Re: 'onfocus' won't work inside dynamic generated <input> li

Posted: Tue Jan 31, 2012 3:17 pm
by social_experiment
Could you paste the code for the javascript function