From: Emre Avsar on
hi guys..

i have this code:

var myhtml = "<tr>" +
"<th style='color:#006296'>" +
standortname +
"</th>" +
"<th>" +
"Standort von: " +
"</th>" +
"<th>" +
"Anzeigen: <input type='checkbox' class='checkbox' name='show'
value='show' onClick='" + createMarker + "'/>" +
"</tr>"

in the checkbox, i want a onClick event:
alert('hello');

i've tried id with doing a variable:
var createMarker = "alert(\'hello\')";
but it doesnt work.

any help?
From: bizt on
On 25 Nov, 16:24, Emre Avsar <emre.avsa...(a)gmail.com> wrote:
> hi guys..
>
> i have this code:
>
> var myhtml = "<tr>" +
>                                                 "<th style='color:#006296'>" +
>                                                         standortname +
>                                                 "</th>" +
>                                                 "<th>" +
>                                                         "Standort von: " +
>                                                 "</th>" +
>                                                 "<th>" +
>                                                         "Anzeigen: <input type='checkbox' class='checkbox' name='show'
> value='show' onClick='" + createMarker  + "'/>" +
>                                         "</tr>"
>
> in the checkbox, i want a onClick event:
> alert('hello');
>
> i've tried id with doing a variable:
> var createMarker = "alert(\'hello\')";
> but it doesnt work.
>
> any help?

what about just:

+ "...value='show' onClick='alert(\"hello\")'/>" +

... personally I prefer double quotes in my HTML so it would be

+ '...value="show" onclick="alert(\'hello\')" />' +

... I think this is valid to XHTML, sure single quotes for tag
attributes are invalid for XHTML although I may be mistaken as Im sure
XML single or double quotes are valid. Im pretty certain onClick
should be onclick though regardless of whether its HTML or XHTML but
is probably only invalid for XHTML

Anyway that should do it

Burnsy
From: Christian Kirsch on
Emre Avsar schrieb:
> hi guys..
>
> i have this code:
>
> var myhtml = "<tr>" +
> "<th style='color:#006296'>" +
> standortname +
> "</th>" +
> "<th>" +
> "Standort von: " +
> "</th>" +
> "<th>" +
> "Anzeigen: <input type='checkbox' class='checkbox' name='show'
> value='show' onClick='" + createMarker + "'/>" +
> "</tr>"
>
> in the checkbox, i want a onClick event:
> alert('hello');
>

If you'd simply generate the DOM with createElement/appendElement, you
could easily attach a Listener to the checkbox - without any quoting
issues and presumably a lot more legible than what you're doing here.
On the same note: If you put your style definitions in an external style
sheet (as opposed to an attribute "style"), you gain more flexibility
and maintainability.