• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript just the spelling!


New Coder
How do I refer/integrate a Javascript-Variable to a Javascript-"Link" like

parent.frames[0].document.forms[0].VARIABLE_CLICK.value = 'X';

More details if needed:
I need to use a last-century frameset (local server, same origins).
frame[1] passes Button-onClick-function (abdamit) data (here: X) to frame[0] and a form there with e.g. 10 form-Elements (here: input/text). Fine.
Theese Elements receiving this data are named/ids 1 to 10. I added a Button-onClick-Counter, value stored in VARIABLE_CLICK and I can pass the Variable-value succesfully instead of „X“. Fine, too.
I need to implement this Variable in the "Link" to call the corresponding Element via ist Name or ID.. I tried much ---(["+.--- which in very far away years helped me then, but now ... silly question?!
<input type="text" name="1" id="1" value="">
<input type="text" name="2" id="2" value="">
<input type="text" name="3" id="3" value="">
function abdamit() {
parent.frames[0].document.forms[0].VARIABLE_CLICK.value = 'X';
<button onClick="abdamit();">BUTTONTEXT</button>


King Coder
I have to say that your description confuses me no end. No matter how often I read it.
But your JS code suggests that you need to access one of 10 elements based on the value of a JS variable.
If so, OldMan's suggestion does look like the way to go. What frames and links have to do with this, no idea....


New Coder
Thank you OldMan, but I made a mistake (surely not only one): I cannot use IDs for reference. And yes, I need to use a frameset. PHP won’t work in this case.
I have a fullscreen slideshow (10 Pics) and 3 (rating-)buttons A, B, C on frame[0] and a function for each of them

var clicksA = 0;
var clicksB = 0;
var clicksC = 0;
var allclicks = 1;

function buttonA() {
clicksA += 1;
parent.frames[0].document.forms[0].A1.value  = 'X';
allclicks += 1;

function buttonB() {
clicksB += 1;
parent.frames[0].document.forms[0].B1.value  = 'X';
allclicks += 1;

function buttonC() {
clicksC += 1;
parent.frames[0].document.forms[0].C1.value  = 'X';
allclicks += 1;

I need to substitute the 'number' 1 (in A1, B1, C1) with the counter 'allclicks' ... something like

parent.frames[0].document.forms[0].A(allclicks).value  = 'X';
parent.frames[0].document.forms[0].B(allclicks).value  = 'X';
parent.frames[0].document.forms[0].C(allclicks).value  = 'X';

the names of the corresponding input text fields on the result-page (frames[1]):

<input type="text" name="A1" value="">
<input type="text" name="B1" value="">
<input type="text" name="C1" value="">

<input type="text" name="A2" value="">
<input type="text" name="B2" value="">
<input type="text" name="C2" value="">

<input type="text" name="A3" value="">
<input type="text" name="B3" value="">
<input type="text" name="C3" value="">

BTW: I am an ‚Old Man‘ too and I just want to ‚refurbish‘ my basic JavaScript-knowledge with this little project.
Cbreeemer: pls excuse my rusty english; hope I made it clear now, what I am looking for!??


King Coder
Haha, as it happens I am an old man too, having been retired for a couple of years now 👴
It's not actually your English that was the problem for me. Just the way the problem was stated, with some terminology I could not understand.
But I think it is kind of clear by now what you are looking for.

You could try this:

parent.frames[0].document.getElementsByName("A"+allclicks)[0].value  = 'X';
parent.frames[0].document.getElementsByName("B"+allclicks)[0].value  = 'X';
parent.frames[0].document.getElementsByName("C"+allclicks)[0].value  = 'X';

This is assuming that you have only ONE element with the name A1, A2, ... in each frame. If that is not the case, I don't know how to go about it. It that is the case, I would personally use the id tag rather than the name tag, so that you could use

parent.frames[0].document.getElementById("A"+allclicks).value  = 'X';
parent.frames[0].document.getElementById("B"+allclicks).value  = 'X';
parent.frames[0].document.getElementById("C"+allclicks).value  = 'X';


King Coder
Thank you! It works! BTW: why does every coder prefer getElemtentsByID instead of getElementsByName? Is there a significant difference?
You're welcome.
Yes there is a significant difference of course. An ID is unique within a document, a name is not. It would depend on the kind and purpose of a field whether you give it an ID or a name (or both). If you have a number of similar fields, a name is handy because you can loop through them using getElementsByName(). If you have a field with unique properties, an ID is handy because you do not need a loop, and can get it with one call to getElementById() (note, nu plural 's' here !)


King Coder
Thank you! It works! BTW: why does every coder prefer getElemtentsByID instead of getElementsByName? Is there a significant difference?

I forgot to mention an important difference between getElementById() and getElementsByName().
If you have an element with an id, you can actually use that id as a variable name in Javascript. No need to call getElementById() !
Try this for example:
<!DOCTYPE html>
<html lang="en">
    <span id="foo"></span>
foo.innerHTML = "Hello !";
I only learned this recently, and was quite amazed by it. This may well explain why using ID's is popular with developers.