Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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!

pb_

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?!
frame[0]
Code:
<input type="text" name="1" id="1" value="">
<input type="text" name="2" id="2" value="">
<input type="text" name="3" id="3" value="">
ff
frame[1]
Code:
var VARIABLE_CLICK = 0;
function abdamit() {
VARIABLE_CLICK += 1;
…
parent.frames[0].document.forms[0].VARIABLE_CLICK.value = 'X';
…
<button onClick="abdamit();">BUTTONTEXT</button>
 
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....
 
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

Code:
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

Code:
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]):

Code:
<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!??
 
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:

JavaScript:
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

JavaScript:
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';
 
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 !)
 
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:
HTML:
<!DOCTYPE html>
<html lang="en">
<body>
    <span id="foo"></span>
</body>
</html>
<script>
foo.innerHTML = "Hello !";
</script>
I only learned this recently, and was quite amazed by it. This may well explain why using ID's is popular with developers.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom