pallavi Posted October 11, 2022 Share Posted October 11, 2022 <div class="custom-select price-option text-center"> <select class="btn-main"> <option id="1" value="1" class="opt-2">3 yrs </span></option> <option id="2" value="2" class="opt-2">2 yrs @ </span></option> <option id="3" value="3" class="opt-2">1 yr @ </option> <option value="4" class="opt-1">6 mths @ </option> <option value="5" class="opt-1">3 mths @ </option> <option value="6" class="opt-1">1 mth @ </option> </select> </div> <div class="price-footer"> <a href="#BestPlans" class="xs-modal-popup btn-two btn-main">Read More</a> <a onclick="change_price()" class="btn-main">Buy Now</a> </div> <script> function change_price(){ document.getElementById("1").innerHTML= "www.youtube.com"; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/ Share on other sites More sharing options...
requinix Posted October 11, 2022 Share Posted October 11, 2022 Since your example does not make sense, I'm going to guess you don't actually want to do this and just need something to demonstrate your question. The most obvious option here would be to change the target of the link when you change the value of the SELECT: give the button an ID and modify its HREF. <a id="buynow" class="btn-main" href="#">Buy Now</a> document.getElementById("buynow").href = "https://www.youtube.com"; Another option is to use the change_price() function to literally browse to that URL, using window.location. window.location.assign("https://www.youtube.com"); Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601517 Share on other sites More sharing options...
pallavi Posted October 11, 2022 Author Share Posted October 11, 2022 using dropdown id then redirect buynow button particular id through passes url ................plz help advanced thank you Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601519 Share on other sites More sharing options...
requinix Posted October 11, 2022 Share Posted October 11, 2022 If you're having a hard time asking a question then post your code. Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601520 Share on other sites More sharing options...
pallavi Posted October 11, 2022 Author Share Posted October 11, 2022 <div class="custom-select price-option text-center"> <select class="btn-main"> <option id="1" value="1" class="opt-2">3 yrs @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['triennially'])-($valPlan['pricing']['INR']['triennially']*1));?> </span> <span>/ mo</span></option> <option id="2" value="2" class="opt-2">2 yrs @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['biennially'])-($valPlan['pricing']['INR']['biennially']*0.5));?> </span> <span>/ mo</span></option> <option id="3" value="3" class="opt-2">1 yr @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['annually'])-($valPlan['pricing']['INR']['annually']*0.0));?> </span> <span>/ mo</span></option> <option value="4" class="opt-1">6 mths @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['semiannually'])-($valPlan['pricing']['INR']['semiannually']*0.3));?> </span> <span>/ mo</span></option> <option value="5" class="opt-1">3 mths @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['quarterly'])-($valPlan['pricing']['INR']['quarterly']*0.4));?> </span> <span>/ mo</span></option> <option value="6" class="opt-1">1 mth @ <span><sup><i class='fa fa-inr'></i></sup> <sup><?php echo $valPlan['pricing']['prefix'];?></sup> <?php echo round(($valPlan['pricing']['INR']['monthly'])-($valPlan['pricing']['INR']['monthly']*0.7));?></span> <span>/ mo</span></option> </select> </div> <div class="price-footer"> <a href="#BestPlans" class="xs-modal-popup btn-main">Read More</a> <a onclick="change_price()" class="btn-main">Buy Now</a> </div> <script> function change_price(){ document.getElementById(1).innerHTML= window.location.assign("https://www.youtube.com"); document.getElementById(2).innerHTML= window.location.assign("https://www.facebook.com"); } </script> Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601521 Share on other sites More sharing options...
requinix Posted October 12, 2022 Share Posted October 12, 2022 Your code does not make sense. The price in your <select> has nothing to do with YouTube or Facebook. You also seem to have no idea how getElementById works or what window.location.assign does. And the markup with the <option>s is confusing. You need to learn about things before you can use them. <form id="abc"> <select name="foo"> <option value="bar" selected>Bar</option> </select> </form> <script> alert(document.getElementById("abc").elements["foo"].value); </script> Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601543 Share on other sites More sharing options...
pallavi Posted October 14, 2022 Author Share Posted October 14, 2022 <form id="abc"> <select name="foo"> <option value="bar" selected>Bar</option> <option value="cat" selected>cat</option> <option value="mat" selected>mat</option> </select> <a id="ab">buy now</a> </form> bar=www.youtube.com cat=www.twitter.com mat=www.facebook.com when i select a option cat n then click on buy now then output will given a particular link on www.twitter.com Now u can understand ! then tell me.............. Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601632 Share on other sites More sharing options...
Barand Posted October 14, 2022 Share Posted October 14, 2022 Perhaps something like this HTML <form id="abc"> <select id="foo"> <option value="">- select -</option> <option value="bar">Bar</option> <option value="cat">Cat</option> <option value="mat">Mat</option> </select> </form> <a id="ab" >buy now</a> SCRIPT <script type='text/javascript'> const urls = { bar:"www.youtube.com", cat:"www.twitter.com", mat:"www.facebook.com" } $(function() { $("#foo").change(function() { $("#ab").attr("href", urls[ $(this).val() ] ) }) }) </script> Quote Link to comment https://forums.phpfreaks.com/topic/315413-when-i-click-on-buy-now-then-open-a-particular-url-javascript/#findComment-1601638 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.