Solved

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

Posted on 2013-01-10
6
269 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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