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

  • Home
  • SEARCH
  • 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 4271248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:24:59+00:00 2026-05-21T07:24:59+00:00

I’m trying to get the value of my div into Javascript. It’s a Drupal

  • 0

I’m trying to get the value of my div into Javascript. It’s a Drupal website and I want to convert currencies and displaying them in a javascript popup.

So far I have this:

<?php 
        print "<script type='text/javascript'>";
        $rate=currency_api_convert("HKD", "CNY");
        print "exchangerate = ".$rate["value"].";";

        print "var $displaycur = getElementById('record-price');";
        print "$displaycur;";

        print "</script>";
?>

And all I get in my browers is:

<script type="text/javascript">
        exchangerate = 0.8406;var  = getElementById('record-price');;
</script>

Although I know the reason why it’s displayed like this, I still don’t know how to get the ID of the div in a proper variable.
Any ideas? Should I use innerHTML?

UPDATE:
A part of the source files:
page.tpl.php

<?php
// $Id: page.tpl.php,v 1.18.2.1 2009/04/30 00:13:31 goba Exp $
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php print $language->language ?>" lang="<?php print $language->language ?>" dir="<?php print $language->dir ?>">
  <head>
    <?php print $head ?>
    <title><?php print $head_title ?></title>
    <?php print $styles ?>
    <?php print $scripts ?>
    <?php 
        // lets get the exchange rate from HKD to RMB, with the help of yahoo finance api and the currency api module
        // we pass the value to javascript, the tooltip will handle the rest
        print "<script type='text/javascript'>";
        $rate=currency_api_convert("HKD", "CNY");
        print "exchangerate = ".$rate["value"].";";
        print "</script>";
    ?>
    <script type="text/javascript">
        function showCurrency() {
            alert('$rate');
        }
    </script>
    <!--[if lte IE 7]>
      <?php print phptemplate_get_ie_styles(); ?>
    <![endif]-->

        <!--[if IE 6]>
            <style type="text/css">
                .fg-menu-ipod .fg-menu li { width: 95%; }
                .fg-menu-ipod .ui-widget-content { border:0; }
                .views-field-field-performer-value { margin-left:-150px;}
                .views-field-field-instruments-value { margin-left:-150px;}
                .coda-nav{display:block; position:absolute; width:400px;height:20px;top:260px;right:100px;z-index:125421;}  </style>
        <![endif]-->


  </head>
  <body<?php print phptemplate_body_class($left, $right); ?>>

And the node-record.tpl.php:

print '<div id="part1-right-line3">';   
    print '<div id="record-price">';                                                        
    print uc_currency_format($node->sell_price);
    print '</div>';                     
    print '</div>'; 
    print '<div id="part1-right-line4">';   
    print '<div id="add-to-cart">';     
    print drupal_get_form('uc_product_add_to_cart_form_'. $node->nid, $node);
    print '</div>'; 
    print '</div>';
    print '</div>';

And here is the output:
enter image description here
Please tell me if you need more, cause there is 🙂
Thanks in advance

  • 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-21T07:24:59+00:00Added an answer on May 21, 2026 at 7:24 am
    <?php 
       print "<script type='text/javascript'>\n";
       $rate=currency_api_convert("HKD", "CNY");
       print "exchangerate = ".$rate["value"].";\n";
       print "var displaycur = document.getElementById('record-price');\n";
       print "alert(displaycur.innerHTML);\n";
       print "</script>\n";
    ?>
    

    I guess ‘record-price’ is ID of your DIV… so displaycur.innerHTML will have everything between <div> and </div>.


    EDIT:

    function showCurrency() {
      alert(document.getElementById('record-price').innerHTML);
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.