alib0ng0
alib0ng0

Reputation: 470

Convert csv coloumn data and output

I have been given a hefty excel file containing a column of 'old' numbers and a column of 'new' numbers next to it.

I have exported this as a csv file

I need to create a html form which will allow the user to input their old number so that it will display the new number.

Any help would be appreciated.

Upvotes: 1

Views: 142

Answers (1)

falsetru
falsetru

Reputation: 369394

http://jsfiddle.net/NsLXt/2/

html

<div>
    <input type="text" id="old-number" placeholder="old number" />
    <button id="convert">convert</button>
    <input type="text" id="new-number" placeholder="new number" readonly />
</div>
<div>
    <input type="text" id="name" placeholder="name" readonly />
    <input type="text" id="city" placeholder="city" readonly />
</div>

coffeescript

conversion =
    15128:
        number: 11599
        name: 'name-of-11599'
        city: 'city-of-11599'
    15129:
        number: 11680
        name: 'name-of-11680'
        city: 'city-of-11680'
    15130:
        number: 11691
        name: 'name-of-11691'
        city: 'city-of-11691'
    15132:
        number: 11694
        name: 'name-of-11694'
        city: 'city-of-11694'
    10097:
        number: 14051
        name: 'name-of-14051'
        city: 'city-of-14051'
    10022:
        number: 14094
        name: 'name-of-14094'
        city: 'city-of-14094'

convert = ->
    old_number = $('#old-number').val()
    new_data = conversion[old_number]
    if new_data
        $('#new-number').val(new_data.number)
        $('#name').val(new_data.name)
        $('#city').val(new_data.city)
    else
        $('#new-number').val('Not found')
        $('#name').val('')
        $('#city').val('')

$('#convert').click(convert)
$('#old-number').keydown (e) ->
    if e.which == 13
        convert()

Upvotes: 1

Related Questions