/    Sign up×
Community /Pin to ProfileBookmark

passing variable from popup to form

Hi,
Below is code for a pop up offer on an order form. Previously, the offer was for two different items, the customer just clicked on the item they wanted, the popup would close & add the selection to the order. Now I want to change it so that the customer will have 4 items to choose from & they enter a quantity for each item.
This script puts a quantity of ONE and a specific item description on the order form, can you please tell me how I would change this script to pass the values that the customer inputs?
Thank you very much!


*****************************************************************

Main Page

Within <HEAD> Section::::::::::::::::::::::::::

<script language=”JavaScript” type=”text/javascript”>

<!– // Begins
function CalculateTotal(frm)
{
var total=0, price, qty, fld, nam;
for (var i=0; i < frm.elements.length; ++i)
{
fld = frm.elements[i];
nam = fld.name;
if (nam.substring(0,4) == “PROD”)
{
price = unescape(nam.substring(nam.indexOf(“_”,5) + 1, nam.length));
qty = unescape(fld.value);
if (qty > 0) total = total + (qty * price);
}
}
var price = Number(frm.elements[“SPECIAL_OFFER_PRICE”].price);
if (price > 0) {
qty = Number(frm.elements[“SPECIAL_OFFER_QTY”].value);
total = total + (qty *
price);
}
var price = Number(frm.elements[“SPECIAL_OFFER_PRICE2”].price);
if (price > 0) {
qty = Number(frm.elements[“SPECIAL_OFFER_QTY2”].value);
total = total + (qty * price);
}
frm.TOTAL.value = total;
}
function specialOffer(frm) {
if(frm.elements[“SPECIAL_OFFER_DESC”].value == “”
&& frm.elements[“SPECIAL_OFFER_DESC2”].value == “”) {
var myWin = window.open(“special_kw_new.htm”, “SPECIAL_OFFER”, “width=600,height=500”);
return false;
}
frm.submit();
return true;
}
function initialValue(frm) {
with (frm) {
elements[“SPECIAL_OFFER_QTY”].saveValue = “”;
elements[“SPECIAL_OFFER_DESC”].saveValue = “”;
elements[“SPECIAL_OFFER_PRICE”].saveValue = “”;
elements[“SPECIAL_OFFER_PRICE”].price = 0;
elements[“SPECIAL_OFFER_QTY2”].saveValue = “”;
elements[“SPECIAL_OFFER_DESC2”].saveValue = “”;
elements[“SPECIAL_OFFER_PRICE2”].saveValue = “”;
elements[“SPECIAL_OFFER_PRICE2”].price = 0;
}
return true;
}
function restoreValue(fld) {
fld.value = fld.saveValue;
return true;
}
// Ends –>
</SCRIPT>

******************************************************************
POP UP Code:

Within HEAD section:::::::::::::::::::::::::::::

<SCRIPT LANGUAGE=”JavaScript”>
<!– // Begins
parentWin = top.opener.top;
parentFrm = parentWin.document.forms[“ORDER_FORM”];

function First_One_Please() {
with (parentFrm) {
elements[“SPECIAL_OFFER_QTY”].value = “1”;
elements[“SPECIAL_OFFER_QTY”].saveValue = “1”;
elements[“SPECIAL_OFFER_DESC”].value = “item description”;
elements[“SPECIAL_OFFER_DESC”].saveValue = “item description”;
elements[“SPECIAL_OFFER_PRICE”].value = “$2.99”;
elements[“SPECIAL_OFFER_PRICE”].saveValue = “$2.99”;
elements[“SPECIAL_OFFER_PRICE”].price = 2.99;
}
}
function Second_One_Please() {
with (parentFrm) {
elements[“SPECIAL_OFFER_QTY2”].value = “1”;
elements[“SPECIAL_OFFER_QTY2”].saveValue = “1”;
elements[“SPECIAL_OFFER_DESC2”].value = “item2 description”;
elements[“SPECIAL_OFFER_DESC2”].saveValue = “item2 description”;
elements[“SPECIAL_OFFER_PRICE2”].value = “$2.99”;
elements[“SPECIAL_OFFER_PRICE2”].saveValue = “$2.99”;
elements[“SPECIAL_OFFER_PRICE2”].price = 2.99;
}
}
function OK_Thanks(opt) {
switch (opt) {
case “First”:
First_One_Please();
break;
case “Second”:
Second_One_Please();
break;
default:
First_One_Please();
Second_One_Please();
}
parentWin.CalculateTotal(parentFrm);
top.close();
}
function No_Thanks() {
parentFrm.submit();
top.close();
}

within PopUp <body> section::::::::::::::::::::::::::::::::::::::::::::

<TD><INPUT TYPE=TEXT NAME=”First” SIZE=1 MAXLENGTH=1></TD><TD>Item 1</TD>

<TD><INPUT TYPE=TEXT NAME=”second” SIZE=1 MAXLENGTH=1></TD><TD>Item 2</td>
<TD><INPUT TYPE=TEXT NAME=”Third” SIZE=1 MAXLENGTH=1></TD><TD>Item 3</TD>

<TD><INPUT TYPE=TEXT NAME=”Fourth” SIZE=1 MAXLENGTH=1></TD><TD>Item 4</td>

<br>
<a href=”javascript?K_Thanks(‘First, Second, Third, Fourth’)”>Add To My Order </a>
<a href=”javascript:No_Thanks();”>No Thanks. </a></center>
**********************
Thank you for any help!

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @cltdesigns 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,
)...