Re: Acess Dynamically Created Elements



bradb wrote:
This is the function that gets called to create the checkbox...

function ent_source(num) {
var str = "source_"+num;
var id_field = "src_over"+num;
var replace = "(Source Over?)<input type=checkbox id='"+id_field+"'
onClick='updateField("+id_field+")'>";
document.getElementById(str).innerHTML = replace;
}

And I get an error immediately after clicking the check box saying
something like:
Error: src_over10 is not defined

Its looking for the object or variable src_over10, you want it to pass
the string "src_over10".

So change this:
var replace = "(Source Over?)<input type=checkbox id='"+id_field+"'
onClick='updateField("+id_field+")'>";

To this:
var replace = "(Source Over?)<input type=checkbox id='"+id_field+"'
onClick='updateField(\'"+id_field+"\')'>";

Notice the two \' around the "+id_field+" , it's probably hard to see.
This will send the string "src_over10" to the updateField function,
which can be used with a getElementById.

You could also do this:
var replace = "(Source Over?)<input type=checkbox id='"+id_field+"'
onClick='updateField(this.id)'>";

Which will do the exact same thing, and save a millisecond or two.

- JS
http://www.endeavorpub.com

.



Relevant Pages

  • Re: Bypassing File Version Dialog on Save
    ... I think you are saying you got Question 2 resolved, ... > Sub CleanCodeInNextFile() ... > Dim OldFileName As String ...
    (microsoft.public.excel.programming)
  • Re: String doesnt auto dup on modification
    ... I'd consider a logger object as a sort of stream. ... do exactly the same thing to a string. ... You seem to be saying this is bad ... because normally objects do not mutate strings which are passed ...
    (comp.lang.ruby)
  • Re: C# Nullable types
    ... string x = null; ... compiler that by using the language specific word called "null". ... so we are given a keyword to state our intentions as the ... I am saying that I don't want x to have any value and I am "ok" with that. ...
    (microsoft.public.dotnet.framework)
  • Re: Access Query Expression - Extremely Urgent!!!
    ... > What you're really saying is you want the first occurrence of 5 numerals ... > in the ItemNumber string. ... Your InPack item is concatenating the result of Expr1. ... > Keith wrote: ...
    (microsoft.public.access.queries)
  • Re: Fundamental theorems, dilemmas, fitness, and information.
    ... I'm not saying YOU are wrong. ... > it totally contradicts for ME what does make sense to me. ... > makes absolute sense to me I have written at another string. ... I did not mean to say the statement "species evolve, ...
    (sci.bio.evolution)