Jump to content

when i click on buy now then open a particular url ..........javascript


pallavi
 Share

Recommended Posts


                            <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>

Link to comment
Share on other sites

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");

 

Link to comment
Share on other sites

 <div class="custom-select price-option text-center">
                                <select class="btn-main">
                                    <option id="1" value="1" class="opt-2">3 yrs  @ &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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 @  &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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 @ &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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 @ &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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 @ &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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 @ &nbsp;<span><sup><i class='fa fa-inr'></i></sup>&nbsp;<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>

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

<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..............

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.