Solved

pop up window with parameter from field on page (ASP / vb)

Posted on 2013-01-10
6
263 Views
Last Modified: 2013-01-10
I have code that pops up a window with a parameter from my recordset.  However, one of the parameters is on the parent page and not yet sent to the database.  How can I alter the code to grab that paramater from the field on the page instead of the recordset ?

The page has 'form1' and field name 'ActualSellPrice'

https://www.teamsxyz.com/WebApps2.0/Media/JDCCalc/JDCCalculator.htm?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "SELLING_PRICE=" & rsQuotes.Fields.Item("SellPrice").Value"%>

I was thinking something like this, but it doesn't work.

https://www.teamsxyz.com/WebApps2.0/Media/JDCCalc/JDCCalculator.htm?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "SELLING_PRICE=" & document.form1.SellPrice.value"%>
0
Comment
Question by:drelinger
  • 3
  • 3
6 Comments
 
LVL 18

Expert Comment

by:nap0leon
ID: 38763406
See if this helps:
http://www.jasondahlin.com/WebSite2/CodeSnippets/JavaScript-Use-Parent-Value-In-Popup.aspx

It shows the code yo place in a pop-up that sets a value in the pop-up to a value from a form-field in the parent-window.
0
 

Author Comment

by:drelinger
ID: 38763598
Thanks for the suggestion, but I'm afraid it won't work in this situation.
I must get the parameters into the URL.
The pop up is to an application not in my control, but was written to pull values from the URL.
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 38763649
"Page 1" has field in it and a link to this popup, right?

e.g.,
page contains a field where the user enters a value:
<input type="text" name="ActualSellPrice" id="ActualSellPrice">

Open in new window

and the page contains a link that opens a popup:
<a href="javascript:void(0)'" onclick="newWindow('SomeURLHere');">Launch pop-up<</a>

Open in new window


If so... a little javascript can set/update the link's URL.
Am I on the right track?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:drelinger
ID: 38763808
yes.  you are on to it.
what syntax for the javascript ?
0
 
LVL 18

Accepted Solution

by:
nap0leon earned 500 total points
ID: 38764008
I'm sure some of this can be optimized.

<!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">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<title>Q_27990980</title>

<style type="text/css">
body {
	color:#000000;
	background-color:#B3B3B3;
	margin:0;
}

#container {
	margin-left:auto;
	margin-right:auto;
	text-align:center;
	}


</style>
<script type="text/javascript">
function LaunchPopup(page,width,height) {
	OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no, scrollbars=yes,resizable=yes, dependent=no,directories=no, width=" + width + ",height=" + height + ",x=50,y=50");
}

function updateLink(value){
	var linkObj = document.getElementById('lnk_LaunchPopup');
	var linkURL = linkObj.getAttribute('data-URL');

	//Some fancy code to split data-URL into parameter:value pairs so you can add or replace the value for "SELL_PRICE" based on the 
	var qLen = linkURL.length
	var qStart = linkURL.indexOf('?') +1;
	var q = linkURL.substr(qStart, qLen);
	var updatedLinkURL = linkURL.substr(0,qStart);
	arrVarsNVals = q.split('&');

	if (arrVarsNVals != '') {
		for (var i = 0; i < arrVarsNVals.length; i++) {
			//locate the existing parameter and value
			thisparam = arrVarsNVals[i].split('=')[0];
			thisvalue = arrVarsNVals[i].split('=')[1];
			if (thisparam == 'SELLING_PRICE') {
				//found SELLING_PRICE parameter, set it to the value in the form
				thisvalue = value;
			}
			updatedLinkURL += thisparam + '=' + thisvalue + '&';
		}
	}

	if (updatedLinkURL != linkURL.substr(qStart)) {
		linkObj.setAttribute('data-URL',updatedLinkURL);
	}
}

</script>
</head>

<body>
	<div id="container">
		<input type="text" name="ActualSellPrice" id="ActualSellPrice" value="" onblur="updateLink(this.value)"/>
		<br/><a href="javascript:void(0);" onclick="LaunchPopup(document.getElementById('lnk_LaunchPopup').getAttribute('data-URL'),'400','180');" data-URL="https://www.teamsxyz.com/WebApps2.0/Media/JDCCalc/JDCCalculator.htm?param1=value1&param2=value2&SELLING_PRICE=" id="lnk_LaunchPopup">Launch pop-up</a>
	</div>
</body>
</html>

Open in new window


This uses an onblur event on the ActualSellPrice field to update the custom attribute "data-URL"  that resides on the link to the popup.  The guts of the updateLink function parse the existing data-URL value to locate the SELLING_PRICE parameter and place the value from the form field into that string.

edit:
Couple notes:
1- this does not handle a default value for ActualSellingPrice  If the field has a value of "5000" in it when the page loads, the URL will not pick up that value (unless you make it do that in your server-side code)
2- After processing through my function, the data-URL attribute has an extra & at the end of it... they ought not hurt anything, but you may check for them and and remove them.
3- this is all easier with jQuery, but you didn't say you had it, so I did it the 'old fashioned' way.
0
 

Author Comment

by:drelinger
ID: 38764502
you got me down the right path - thank you...
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now