Solved

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

Posted on 2013-01-10
6
267 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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