• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Another Firefox jscript conversion problem

xoggoth

More fingers than teeth
Joined
Jul 8, 2005
Messages
17,133
Likes received
4,950
Thanks received
1,184
Location
xoggoth towers
In IE I am using a recordset object:-

<OBJECT ID="key_yesno"
CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<PARAM NAME="DataURL" VALUE="keys.csv">
<PARAM NAME="UseHeader" VALUE="True">
<PARAM NAME="TextQualifier" VALUE=",">
</OBJECT>

It allows for a scroll button to read various values from a csv file using key_yesno.recordset.MoveNext() and inserts them into INPUT HTML elements
eg <input type=text DATASRC="#key_yesno" DATAFLD="name0">.

I could just shove the values in hidden HTML elements but before I fanny about doing that is there an equivalent that works in firefox and the other browsers? Can't seem to find one on net.

Cheers for usual brilliant replies.

PS This needs to run on PC not just online.
 
Last edited: 12:49
Nope, your example uses IE's databinding stuff, which was only ever a proprietary Microsoft extension.

One possibility would be to convert your CSV file to a JavaScript object or array literal (very similar to JSON, which is what all the other browsers including IE 8 have moved towards), which you could load using <script src="keys.js"></script> where "keys.js" would contain something like:

Code:
var values = {
    "key1": 2,
    "key2": "Value of key 2",
    "foo": "bar",
    "baz": ["array", "of", "strings", "and", 1, "number"] 
};

The variable values can then be iterated over; assuming that the key is the name of the input field and the value is the value of the input field, something like:

Code:
var elements = document.getElementById("myForm").elements;
for (var name in values) {
    if (!!elements[name]) {
        elements[name].value = values[name];
    }
}

(It gets slightly more complicated if you want to set the currently-selected values of things like SELECT elements...)
 
Last edited: 14:08
Hey ta again Nick! That looks very suitable as it needs to be in a separate file for preference.

Update. All working now. Ta again.
 
Last edited: 15:30

Advertisers

Back
Top