Forum Moderators: open

Message Too Old, No Replies

Hierarchy

         

Bobby_Boy7

3:12 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Trying to do a for statement for a bunch of buttons.
document.frames[a].form[b].button?[c]

i don't know what the button really is. Could it be input[x], radio[x], etc?

Bernard Marx

5:30 pm on Apr 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't think so. I've never heard of a 'buttons' collection, but maybe there is. If you want any form element, use the 'elements' collection.

Can you be more specific?

BTW, you're missing the 's' off 'forms'.

Bobby_Boy7

5:57 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Thanks for you effort. What i am trying to do is get a variable to save when a button is clicked so that each button can work with the same function. If i use an array, a quick for and nested if statement will serve perfectly. As of now, i have one function programmed for each button. Which sucks. Here is something what it would look like:

function buttonpress()
{

for(v=0 ; v<=5; v=v+1)
{
if(document.forms[0].button/element[v].selected)
{
variable = document.forms[0].button/element[v].value;
}
}

var newlink = variable + '.html';
parent.frames[2].location= newlink;
}

But i don't know the button/element[v] array which means i have to refer to their names such as button1, button2, etc. I can't do it this way with a a for statement because the names are different. Maybe an button array or a struct?
Thanks

ajkimoto

6:21 pm on Apr 16, 2004 (gmt 0)

10+ Year Member



Bobby_Boy7,

Why not just pass an object reference to the function from each button?

<script type="text/javascript">
<!--

function buttonpress(obj)
{
variable=obj.id
var newlink = variable + '.html';
parent.frames[2].location= newlink;
}

//-->
</script>
</head>

<body>

<button id="newpage1" onclick="buttonpress(this)">newpage1</button>
<button id="newpage2" onclick="buttonpress(this)">newpage2</button>

</body>

You can set up a global click-handling function that accesses the clicked element instead, but this is easier to implement.

ajkimoto