Hi, am working on a form with 2 variables. One drop down has designation and another add-on.
Drop down 1: Designation (Des1-INR500, Des2-INR750, Des3-INR1000)
Drop down 2: Add-on (Add1-INR100, Add2-INR200, Add3-INR300)
Value: Total Amount is {based on ddl1 and ddl2 selection)
Now, based on the selection I want to show the values in a different field and then take the value to the Payment Gateway for payments. The catch is, the code should work based on the IP. For Indian IP, the price is as above. For others, the Total Amount is a fixed $50.
Below are my codes:
First script below:
script type="text/javascript">
var rates = {"des1: 500, "des2": 750, "des3": 1000};
var addon = {"add1": 100, "add2": 200, "add3": 300};
$('#designation, #addon').change(function(){
changeAmount();
});
function changeAmount()
{
var fromKey = $('#designation').val();
var from = rates[fromKey];
var fromAddon = $('#addon').val();
var addon= addon [fromAddon];
var to = $('#fixedAmt').val();
var ans = to * ( from + archive);
ans = +ans || " "
document.getElementById("varAmt").innerHTML = ans;
}
</script>
Second script below:
script type="application/javascript">
function geoip(json){
// Get country code based on IP
var country_code = json.country_code;
// Set dynamic values in an object
var price_obj = {
prices: {
IN: 1,
}
},
get_price = price_obj[ 'prices' ][ country_code ];
// Check if we have a price for the visitor's country, if not we'll set a default of $12.99
if(get_price == null) {
display_price = 50;
} else {
// Else the price does exist is the array
display_price = get_price;
}
// Set dynamic values in an object
var curr_obj = {
currencies: {
IN: 'INR ',
}
},
get_curr = curr_obj[ 'currencies' ][ country_code ];
// Check if we have a price for the visitor's country, if not we'll set a default of $12.99
if(get_curr == null) {
display_curr = 'USD ';
} else {
// Else the price does exist is the array
display_curr = get_curr;
}
var str2 = "Registration Fee: ";
var res2 = str2.concat(display_curr).concat(display_price);
$('#fixedAmt').html(display_price);
document.getElementById("fixedAmt").value = display_price;
document.getElementById("fixedCurr").innerHTML = display_curr;
}
</script>
script async src="https://get.geojs.io/v1/ip/geo.js"></script>
form action="forms/book.php" method="post" role="form" class="php-email-form" data-aos="fade-up" data-aos-delay="100">
div class="form-row">
div class="col-lg-4 col-md-6 form-group">
select input type="text" class="form-control" name="designation" id="designation" placeholder="Designation" data-rule="minlen:4" data-msg="Please select an option">
option value="des1" disabled selected>I'm a</option>
option value="des2">Post Graduate</option>
option value="des3">Consultant</option>
</select>
<div class="validate"></div>
div class="col-lg-4 col-md-6 form-group">
select input type="text" class="form-control" name="addon" id="addon" placeholder="Add-on" data-rule="minlen:4" data-msg="Please select an option">
option value="add1" disabled selected>Add on for INR 100</option>
option value="add2">Add on for INR 200</option>
option value="add3">Add on for INR 300</option>
</select>
<div class="validate"></div>
</div>
//the below code is used to get value from one script and post to other script (kind of messy way)
input type="text" name="FIXED_AMT" id="fixedAmt" readonly hidden>
</div>
<!--<div class="text-center"><button type="submit" value="Validate" onclick="return Validate()"><div id="varAmt"></div></button></div>-->
div class="form-row">
div class="col-lg-6 col-md-6 form-group">
div class="text-left amountstyle">Registration Fee: <span id="fixedCurr"></span><span id="varAmt"></span></div>
</div>
div class="col-lg-6 col-md-6 form-group">
div class="text-right"><button type="submit" value="Validate" onclick="return Validate()">PAY NOW</button></div>
</div>
</div>
</form>
I’ve removed ‘<’ in front of the codes for the preview.
It doesn’t work together. only either of the scripts are working. am new to JS. can some one help on how to combine both and have as one script?
The requirement is, if the user is inside Indian IP, then based on the drop-downs, take the values and calculate and show the final value (Total Amount). If the user is outside Indian IP show only USD 50 as the final value (Total Amount).