/    Sign up×
Community /Pin to ProfileBookmark

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

[CODE]<div class=’pcontainer’>
<label for=’words’ >Words:</label><br/>
<span id=”words”> </span><br/>
<span id=’contactus_email_errorloc’ class=’error’></span>
</div>
<div class=’pcontainer’>
<label for=’tprice’ >Price:</label><br/>
<span id=”tprice”> </span><br/>
<span id=’contactus_email_errorloc’ class=’error’></span>
</div>[/CODE]

Because the transition from form.php to proces.php is a re-direct and not a form action, could i still use POST/GET?

[CODE]<?PHP
session_start();

$_SESSION[“price”] = $_GET[“tprice”];
[/CODE]

Any help would be greatly appreciated,

Thanks!

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@JoeHillyardauthorMay 30.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?

Thanks
Copy linkTweet thisAlerts:
@deathshadowMay 30.2014 — 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:

var
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.
Copy linkTweet thisAlerts:
@JoeHillyardauthorMay 30.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 :

[CODE]
var
words = getText('words'),
tprice = getText('tprice');
[/CODE]


Are they global variables which could be used on another page ?
Copy linkTweet thisAlerts:
@ginerjmMay 30.2014 — 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.
Copy linkTweet thisAlerts:
@JoeHillyardauthorMay 30.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.
Copy linkTweet thisAlerts:
@deathshadowMay 31.2014 — Are they global variables which could be used on another page ?[/QUOTE]
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.
Copy linkTweet thisAlerts:
@JoeHillyardauthorJun 01.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).

[CODE]
<script type="text/javascript">

var pfinal = localStorage.getItem("pprice");

var npfinal = parseFloat(pfinal).toFixed(2);

alert(npfinal);

</script>
[/CODE]


The alert displays a perfectly normal, 2 decimal number, however when i put this:
[CODE]
<input type="hidden" name="amount" value="npfinal">
[/CODE]


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!

Thanks
Copy linkTweet thisAlerts:
@deathshadowJun 01.2014 — 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.
×

Success!

Help @JoeHillyard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...