• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • 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

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    Another Firefox jscript conversion problem

    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 by xoggoth; 15 September 2009, 11:51.
    bloggoth

    If everything isn't black and white, I say, 'Why the hell not?'
    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

    #2
    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 by NickFitz; 15 September 2009, 14:52. Reason: Oops, typo in variable name...

    Comment


      #3
      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 by xoggoth; 15 September 2009, 17:19.
      bloggoth

      If everything isn't black and white, I say, 'Why the hell not?'
      John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

      Comment

      Working...
      X