PDA

View Full Version : Convert string to logic


Relaxasaurus
02-07-2008, 09:25 PM
I basically have values in an alt tag that are separated by commas. I want to convert that to an array...

<input type="radio" id="TEST" alt="'medicine','diet','health'" />

var alt = document.getElementById('TEST').alt;
var alt_array = new Array([alt]);
alert(alt_array[0]);

The above code returns 'medicine','diet','health' but I want it to return just medicine

Thank you for any help!

Andrew Johnson
02-07-2008, 09:29 PM
Have you considered changing the ALT value to "medicine,diet,health" and just using the split javascript function?

http://www.w3schools.com/jsref/jsref_split.asp

Relaxasaurus
02-07-2008, 09:47 PM
Worked beautifully, thanks! So simple, but I hate to say I spent about an hour tweaking & then searching for a post just like yours ;P

Andrew Johnson
02-07-2008, 09:58 PM
Haha, that's how it goes in this business. Glad I could help - I was going to write out a script for you but I got lazy and just posted a URL. I suppose all's well that ends well!