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 8464059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:37:37+00:00 2026-06-10T14:37:37+00:00

Is there a way I can pass the php option value variable $option_value[‘price’] into

  • 0

Is there a way I can pass the php option value variable $option_value[‘price’] into javascript as a string, then each time a different option is chosen, the javascript ‘updates’ the string with the new value. I have tried with onchange() but must be doing something wrong. I am sure my mistake is because php is server side and javascript is client side, but I have no idea how to get the two to act how I want.

<?php if ($options) { ?>
    <?php foreach ($options as $option) { ?>
    <?php if ($option['type'] == 'select') { ?>
    <span id="option-<?php echo $option['product_option_id']; ?>" class="option">

<select name="option[<?php echo $option['product_option_id']; ?>]" onchange="getIt(this)">
        <?php foreach ($option['option_value'] as $option_value) { ?>
        <option value="<?php echo $option_value['product_option_value_id']; ?>"><?php echo $option_value['name']; ?>
        <?php if ($option_value['price']) { ?>
        <?php $option_value['price']; ?>
        <?php } ?>
        </option>
        <?php } ?>
      </select>
</span>

I have tried:

<script type="text/javascript"> 
function getIt(elm) {
var val = elm.options[elm.selectedIndex].text;
window.alert(val);
}
</script>

and

<script type="text/javascript">
function getIt() {
var val = "<?php $option_value['price']; ?>";
window.alert(val);
}
</script>
  • 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-06-10T14:37:39+00:00Added an answer on June 10, 2026 at 2:37 pm

    Here is an example how you can do it. What you have to do are:

    1. Analyze the code (notice that I use jquery from google’s account. You will need to at some point install jquery on your web site and use this one instead of the google’s one.
    2. Build your fruits array so it looks like the one in the example.

    I have prepared page that will show you this working here: http://jsfiddle.net/7uudp/

    Below is what it contains. Notice that this example does not use your variables. You will need to use them the way you want/need. I have also defined entry_fruit to show you how to chose the default one to be selected. Hope it will help.

    <html>
    <head>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
    <script type="text/javascript">
    
    fruits = [{n:"apple",p:1},{"n":"strawbery",p:3}];
    entry_fruit="strawbery";
    
    function build_select(select,list,which)
    {
        $.each( list, function(i,v){
             var selopt="" ;
             if ( v.n == which ) selopt="selected" ;
             $(select).append("<option "+selopt+" value="+i+">"+v.n+" - $"+v.p+"</option>");
         }) ;
    }
    
    $(document).ready(function(){
        build_select($("select[name=fruits]"),fruits,entry_fruit);
         $("select[name=fruits]").change(function(){
             alert("Price is $" + fruits[$(this).val()].p);
         }) ;
    })
    
    </script>
    </head>
    <body>
    <select name="fruits"></select>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can pass a PHP variable from a PHP page
I am wondering if there is a way I can pass an updated PHP
Is there any way that I can pass arguments in selector? example: I have
I was wondering if there is a way that I can pass variables like
i'm trying to pass a php defined string with spaces to a javascript function,
Is there any way I can pre-process a PHP view script without using a
Possible Duplicate: How to pass a variable / data from javascript to php and
Is there any way can declare a bean in just like JSP UseBean in
Is there way that I can read the file from remote server using fopen
Is there any way I can set a formatter on models that will convert

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.