Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7586587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:27:53+00:00 2026-05-30T19:27:53+00:00

I am trying incorporate some javascript within the php below to pass a variable

  • 0

I am trying incorporate some javascript within the php below to pass a variable to the next page (checkout.php). It worked initially, but now I am having trouble executing this properly. Any tips?

    echo '<div class = "row"><div class = "span 4 offset6"><select style="width:                130px;" name="shipping" class="span2">
            <option value="0">7-9 days: FREE</option>
            <option value="7">3-5 days: $7</option>
                                    <option value="17">2 days: $17</option>
            <option value="22">1 day: $22</option>
            </select></div></div>';
            }


    echo '<script language="javascript">
    function test()
    {
        var val=document.getElementById("select").value;  
        var hrf="checkout.php?options="+val;
        document.getElementById("a_link").href=hrf;
    }
    </script>
    <a href ="#" id="a_link" onclick="test();" class="btn btn-success" type="submit"><i class="icon-shopping-cart icon-white"></i>  Add to Cart</a>';

EDIT: The problem I having is that when I click on the button, it stays on the same page instead of going to checkout.php with the option parameter.

Even when I change the first line of the javascipt to:
var val=document.getElementByName(“shipping”).value;
The page still stays the same. I’m assuming this is where the issue is but I odn’t know how to fix it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:27:54+00:00Added an answer on May 30, 2026 at 7:27 pm

    Just do not incorporate JS within PHP. There is absolutely no point in this!
    Just leave PHP mode and write JS as is:

    <?php
    //some PHP
    ?>
    <script language="javascript">
    function test()
    {
        var val=document.getElementById("select").value;  
        var hrf="checkout.php?options="+val;
        document.getElementById("a_link").href=hrf;
    }
    </script>
    <a href ="#" id="a_link" onclick="test();" class="btn btn-success" type="submit">
    <i class="icon-shopping-cart icon-white"></i>  Add to Cart</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to incorporate some JavaScript unit testing into my automated build process. Currently
I'm trying to incorporate validation into some of my models, but when doing that,
I'm trying to incorporate some Gravatar functionality using its XML-RPC API in an iPhone
I'm trying to incorporate some plots from R in my LaTeX document through Sweave.
Using C#, asp.net 3.5, SqlServer 2005, Trying to incorporate some inversion of control together
I am trying to pass an XML list to a view but I am
I am trying to incorporate some HTML into a silverlight application however even commercial
I am trying to populate a TreeView in silverlight, but I am having some
I'm trying to incorporate some design-by-contract techniques into my coding style. Postconditions look a
I'm trying to incorporate some sort of error handling into an iOS app. After

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.