Results 1 to 9 of 9

Thread: Passing span value to PayPal

  1. #1
    Join Date
    May 2014

    Passing span value to PayPal

    I have a js script which prints a value to innerText of a span. I am trying to take this value and pass it onto paypal as an amount.

    The process goes:

    form.php --> process.php --> PayPal

    Because i am using a script i found online i cannot go directly to PayPal as the form action is already set to the send.php. Therefore i need to pull the value from span in form.php, into process.php and then into PayPal. I have tried using $_SESSION variables but it didn't work and when i var_dumped the session it showed an array when i was expecting a simple integer.

    Im not quite sure which code is useful/relevant

    <div class='pcontainer'>
        <label for='words' >Words:</label><br/>
        <span id="words"> </span><br/>
        <span id='contactus_email_errorloc' class='error'></span>
    <div class='pcontainer'>
        <label for='tprice' >Price:</label><br/>
        <span id="tprice"> </span><br/>
        <span id='contactus_email_errorloc' class='error'></span>
    Because the transition from form.php to proces.php is a re-direct and not a form action, could i still use POST/GET?

    $_SESSION["price"] = $_GET["tprice"];
    Any help would be greatly appreciated,


  2. #2
    Join Date
    May 2014
    Essentially all i need to do is get the value of the span into a variable, is this possible or could anyone recommend a better way?


  3. #3
    Well, you have ID's on them, so innerText on the element would be easiest. For example your "words" property... I'd probably make a function for that to do the getElementById and the cross browser innerText thus:

    function getText(id) {
      var e = document.getElementById(id);
      return e ? (e.innerText || e.textContent) : false;
    Then you could just:

      words = getText('words'),
      tprice = getText('tprice');
    ...and so forth.

    Though I have to ask, why do you have LABEL pointing at SPAN? LABEL is for INPUT, TEXTAREA and SELECT inside a FORM, (preferably with a FIELDSET wrapping said form elements). If you really are going to use LABEL, maybe you should use a <input type="readonly"> since it's far easier/reliable/faster to read .value from an INPUT than innerText from a span.

  4. #4
    Join Date
    May 2014
    Thanks for the help, i apologize for my very limited knowledge!

    The label's are inside a fieldset which is inside a form! haha

    So after :

      words = getText('words'),
      tprice = getText('tprice');
    Are they global variables which could be used on another page ?

  5. #5
    Join Date
    Jul 2013
    Voorheesville NY USA
    You STILL have label tags pointing to a span tag - not what they are used for.

    Regarding your limited knowledge: Not knowing how this 'link' to a paypal process is going to facilitate whatever you are doing, but does your limited knowledge provide you with the right concerns for security and input validation and protection against potential malfeasance with your paypal connection? If I were you I would NOT be using my current skillset for such advanced (and perhaps tragic?) implementations.

    PS - It's not nice to laugh at people who are attempting to help you, while still ignoring what they told you.

  6. #6
    Join Date
    May 2014
    Firstly i wasn't laughing at him, i meant it as light humour.

    And yes i am probably a bit out of my depth but i have found over time that this is the fastest way i learn, but i wouldn't jeopardise someone's website until i understand what i am doing and implement it correctly.

  7. #7
    Quote Originally Posted by JoeHillyard View Post
    Are they global variables which could be used on another page ?
    They are global in terms of JavaScript, but couldn't be used on other pages because when you refresh the page globals are erased. To get them to another page you'd have to submit them as formdata, use javascript with AJAX to pass them in a fake form or as URI getData, or store it in a cookie.

    Oh, and don't sweat the 'haha' -- it's good to hear you at least have the form and fieldset part right, it's just those SPAN don't make any sense. LABEL are for INPUT, SELECT and TEXTAREA -- and that's IT. You don't use them to point at other tags.

    REALLY looking at this, it starts to sound like you should just be using readOnly input and doing normal form submissions, instead of playing with JavaScript, but that's really hard to dial in closer without seeing the full form.

  8. #8
    Join Date
    May 2014
    Appreciate the understanding!

    I have made an advance but have come across another problem.

    I got the variable to the next page using local storage, formatted the variable to a float with 2 decimal places (correct paypal format).

    <script type="text/javascript">
    		var pfinal = localStorage.getItem("pprice");
    		var npfinal = parseFloat(pfinal).toFixed(2);
    The alert displays a perfectly normal, 2 decimal number, however when i put this:
    <input type="hidden" name="amount" value="npfinal">
    It says it is incorrectly formatted.

    I know the topic has slightly changed and the post may now be in the wrong place, but if anyone has any info would be great!


  9. #9
    value has to be that value, you can't just say a javascript variable name as a value, all you've done is set value to the STRING "npfinal" and passing that to PP. Markup does NOT have access to JavaScript variables.

    put an ID on that input like:
    <input type="hidden" name="amount" id="hiddenAmount" value="0" />

    Then in JavaScript:
    document.getElementById('hiddenAmount').value = npFinal;

    You could also reference it by it's form using it's NAME, but that's really more of a Nyetscape 4 style scripting that's frowned upon in modern circles.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17095 seconds
  • Memory Usage 2,932KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (7)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (9)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates