Jump to content

Can I set the ID of a tag programatically?


Emerogork

Recommended Posts

This is a very difficult question to explain. Other approaches will be considered.

 

If I posted the code/program, you would find it useless believe it or not. If you believe not then I will post it on your request and prove my point. (: The program I am using accepts code through a template and therefore is not, in itself executable code. The user calls for templates as needed. To see this in action, you would need a server with Moodle (Linux, Apache, PHP5, etc) running and have the Generico Filters plugin installed. If you do, and you understand the program, then I could send you the .txt file.

 

Ok, so this has to be solved theoretically instead of practically.

 

Here is the line of code that I can use to send the date called stopdate2a as an ID in a span used in the HTML program.

 

(JS) document.getElementById("StartDA").innerHTML = stopdate2A;

(HTML) <p>@@Message@@<span id="StartDA"> Stop Date </span></p>

 

“Stop Date” gets replaced by the date in stopdate2a.

It works fine if I am using only one template.

 

The Javascript functions and the HTML page get called for each template and the StartDA span ID is in many separate instances of HTML therefore the use of <span id=StartDA></span> can be used. The problem is that the function in JS generates a new value of StartDA and each instance is to be used in a different location. At the moment, StartDA appears the same value everywhere. The problem is that it is to be unique.

 

Since I presently need 25 templates I need to be able to identify each instance of StartDA. If I could send "StartDA" as a variable instead of text, I could use something like an array such as StartDA(X) and increment X as needed.

 

I am sure that if I used document.getElementByclass("StartDA").innerHTML = stopdate2A; that I would have the same problem.

 

I will leave it there for now to see if anyone can make any sense out of all this and see what questions/remedies are proposed.

 

 

Link to comment
Share on other sites

The length of That your script will not stop you from posting them, You need to post them or upload it online so we can take a closer look on it. Also, you need to be specific. Always go step-by-step while creating a code. Be sure of what a code does before even trying to copy them. Because a code you wrote by yourself will never be complicated. That so called "copy and start using" that is where you will encounter problem.

Edited by Chikwado
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...