javascript - Using jQuery / JS to switch form values fails when value contains a '/' -
i'm using switch function unit converter allows user swap units instead of changing selection. works fine noticed in cases failed.
i went through options until reducing size of value field/ worked. assumed value long after checking on here:
max length of html attribute value
it looks within boundaries. i'm wondering else be?
below 2 examples taken console log showing before , after switch button pressed , results once changed name.
measurement type: thermalexpansion convertfunctions.js:30before!!! from: length/length/degreec to: length/length/degreeran convertfunctions.js:40after!!! from: length/length/degreec to: length/length/degreeran convertfunctions.js:1020parsed input 1 , result 0.555555556 measurement type: thermalexpansion convertfunctions.js:30before!!! from: lengthran to: lengthk convertfunctions.js:40after!!! from: lengthk to: lengthran
edit: tested again using oblique in field , failed.
edit again: more info:
the function, shows console logs generated
function switchunits(){ //need values before swap , around. var = $("#from").val(); var = $("#to").val(); console.log('before!!! from: ', from, 'to: ', ); //switches details $("#to #"+from).attr("selected","selected"); $("#from #"+to).attr("selected","selected"); //gets values after switch = $("#from").val(); = $("#to").val(); console.log('after!!! from: ', from, 'to: ', ); //run convert convertunits(); }
example of json file once edited remove '/' value field
before edit example:
"thermalexpansion":[ { "value": "length/degreek", "name" : "length / length / kelvin (1/k)" }, ],
after edit example:
"thermalexpansion":[ { "value": "lengthk", "name" : "length / length / kelvin (1/k)" } ],
Comments
Post a Comment