I am storing multiple values in a select option and trying to get the all the values separately by splitting the value. Split seems to work as I can get the first [0] value, but I am not getting any value after that. It alerts back as undefined. Code below. Thanks.
function roi_calc(e) {
var merchant_option = $(e).prev('td').prev('td').prev('td').find('select').val();
if (merchant_option!='Merchant') {
var value_input = $(e).prev('td').prev('td').find('input').val();
if ((value_input!='') && (value_input!='Value')) {
var price_input = $(e).prev('td').find('input').val();
if ((price_input!='') && (price_input!='Price')) {
alert ('Merchant value = '+merchant_option);
//var price_arr = new Array();//tried setting array first, but same results
var price_arr = price_input.split(',',3);
//alert (price_arr);//alerts '1'
alert (price_arr[0]);//working - alerts '1'
alert (price_arr[1]);//not working - undefined
alert (price_arr[2]);//not working - undefined
}
else {alert ('Price must be entered.');}
}
else {alert ('Value must be entered.');}
}
else {alert ('Merchant must be selected');}
//alert (row_option);
}
HTML
<table style="width: 600px;">
<tr>
<td>
<select>
<option>Merchant</option>
<option value="1,2,3,4">1</option>
<option value="5,6,7,8">2</option>
</select>
</td>
<td><input value="Value"></td>
<td><input value="Price"></td>
<td onclick="roi_calc(this);"> R.O.I </td>
</tr>
</table>
on jsfiddle http://jsfiddle.net/upywN/
FOUND THE ANSWER. Stupid mistake on my part.
I was splitting price_input, but needed to be splitting merchant_option stupid mistake sorry to waste everyone's time.