JSFiddle - React, Tailwind, and code Playground
by kontrach
HTML
<select id='fid' name="billingcycle" onchange="addOffer();"> <!-- id to get the whole select object-->
<option value="monthly" selected="selected">1 Month Price - $7.95 USD</option>
<option value="semiannually">6 Month Price - $6.95 USD</option>
<option value="annually">12 Month Price - $6.45 USD (Free Domain)</option>
<option value="biennially">24 Month Price - $5.95 USD (Free Domain)</option>
</select>
<select id="result"></select>
JavaScript
/*var option,i, appendText, length, price, startPrice, endPrice, beforePriseStr, afterPriseStr, numOfOptions, optionElement;
optionElement = document.getElementsByTagName("option");
numOfOptions = optionElement.length;
for( i = 0; i < numOfOptions; i++){
//while(numOfOptions){
option = optionElement[0].firstChild.nodeValue;
document.getElementById("fid").removeChild(optionElement[0]);
length = option.length;
for(j = 0; j < length; j++){
if(option[j] == '$'){
startPrice = j + 1;
}
if(option[j] == 'U'){
endPrice = j - 1;
}
}
price = option.substring(startPrice, endPrice);
beforePriceStr = option.substring(0, startPrice);
afterPriceStr = option.substring(endPrice);
price = price / 2;
appendText = "<option>" + beforePriceStr + price.toFixed(2) + afterPriceStr + "</option>";
document.getElementById("fid").innerHTML += appendText;
// numOfOptions--;
}
*/
var optionArray = [], option, i, start, end, newPrice, oldPrice;
option = document.getElementsByTagName("option");
for( i = 0; i < option.length; i++){
optionArray[i] = option[i].firstChild.nodeValue;
start = optionArray[i].indexOf('$') + 1;
end = optionArray[i].indexOf(' U');
//optionArray[i] = optionArray[i].substr(start, (end - start));
oldPrice = optionArray[i].substr(start, (end - start));
newPrice = (oldPrice / 2).toFixed(2);
alert(oldPrice);
alert(newPrice);
optionArray[i].replace(oldPrice, newPrice);
}
alert(optionArray);
//alert(price);