?
Solved

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

Posted on 2013-01-10
6
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

765 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