PDA

View Full Version : codiga button reference in javascript



eydg
11-04-2012, 08:03 AM
A button in form like this


<form name="WHO">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend></legend>
<input type="radio" name="ACTION" id="ACTION_0" value="1" accesskey="1" onclick="jazda()" />


is addressed in js in the following way:


document.WHO.ACTION.length

Then how to replace that one with such a button:

<a data-role="button" data-inline="true" href="#page1" data-icon="arrow-l" data-iconpos="left">
Button
</a>


Put it into a form yes, but value doesn't work here. How to do without?

Dormilich
11-05-2012, 10:11 AM
Put it into a form yes, but value doesn't work here.
of course, since it ain’t a form element, you can neither use the form access syntax, nor does the "button" have a value property.

for access you’ll need standard DOM accessors (a là document.getElementById()) and for the value-property you have to use the according property of the <a> element (whatever that is in this case).

NOTE: document.WHO.ACTION.length refers either to the size of the HTMLCollection returned by document.WHO.ACTION or, if it is a single element, undefined.

ATTENTION: action is a property of the form element itself, so in the worst case, you don’t access a form element, but the target URL of the form (which, as a string, also has a length property).

eydg
11-07-2012, 01:39 AM
Okay, so there is this piece of code:


<a data-role="button" data-inline="true" data-direction="reverse" data-icon="arrow-r" data-iconpos="right" id="participant1" ></a>

<a data-role="button" data-inline="true" data-direction="reverse" data-icon="arrow-r" data-iconpos="right" id="participant2" ></a>


but according to dreamweaver, these do not go with "checked".

How to refer to the status of such a radiobutton?

Old Pedant
11-07-2012, 02:11 AM
One more time, those are *NOT* radio buttons.

If they are something that DreamWeaver has NIGHTMARED-up for you, then you will need to refer to the DrunkWalker dccumentation to find out how DoofusWhacker uses them.

If this is designed for use with something like ARIA, then refer to the ARIA documentation.

But no matter what, those are *NOT* radio buttons.

eydg
11-07-2012, 01:07 PM
Is it just you who hates the program, or should I beware mentioning it on the forum?

I took the piece of code from a framework named codiga.


<a data-role="button" data-inline="true" href="#page1" data-icon="arrow-l" data-iconpos="left">
Button
</a>
<a data-role="button" data-inline="true" data-direction="reverse" href="#page1" data-icon="arrow-r" data-iconpos="right">
Button
</a>

The above does behave as a radiobutton, i.e. there are two butts and they switch as you press one.

I need them to reference their status in script, but maybe i will just register on codiga if the code used is not universal enough.

Dormilich
11-07-2012, 02:21 PM
The above does behave as a radiobutton, i.e. there are two butts and they switch as you press one.

when they behave like a radio button does not mean they are radio buttons. that may not be a problem in GUI, but the programming interfaces of an <a> element and an <input> element are worlds apart:


// an <a> element (a fake radio button)
interface HTMLAnchorElement : HTMLElement {
attribute DOMString accessKey;
attribute DOMString charset;
attribute DOMString coords;
attribute DOMString href;
attribute DOMString hreflang;
attribute DOMString name;
attribute DOMString rel;
attribute DOMString rev;
attribute DOMString shape;
attribute long tabIndex;
attribute DOMString target;
attribute DOMString type;
void blur();
void focus();
};

// <input> element (a real radio button)
interface HTMLInputElement : HTMLElement {
attribute DOMString defaultValue;
attribute boolean defaultChecked;
readonly attribute HTMLFormElement form;
attribute DOMString accept;
attribute DOMString accessKey;
attribute DOMString align;
attribute DOMString alt;
attribute boolean checked;
attribute boolean disabled;
attribute long maxLength;
attribute DOMString name;
attribute boolean readOnly;
// Modified in DOM Level 2:
attribute unsigned long size;
attribute DOMString src;
attribute long tabIndex;
// Modified in DOM Level 2:
attribute DOMString type;
attribute DOMString useMap;
attribute DOMString value;
void blur();
void focus();
void select();
void click();
};

Old Pedant
11-07-2012, 09:24 PM
It's okay to use DreamWeaver. Just don't expect it to produce very good JavaScript (or PHP or ASP, if you are using it for those) code. Depending on what you are doing, in fact, it might produce really horrible code.

I don't think the code in this case is horrible, but it's certainly not made clear to you, the user of it, that what it is creating is in now way a radio button and you certainly can not treat it as such.

What is happening is that DW is adding some kind of code BEHIND THE SCENES to make those <a> links *look* like radio buttons. And if you intend to use them to replace normal radio buttons, then you will have to very carefully read and understand the DW documentation on how they work and how you may be able to use them for that purpose.