[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 406
  • Last Modified:

appending values to a URL variable based on <SELECT> element

I don't know if this is even possible. In the attached code snippet, what I want is that when the user changes the value of the <SELECT> element (onChange?), the VALUE part of the param element needs to be modified so that the value of <SELECT> goes after the "variable=".

So if the user highlights the 2nd <SELECT> option, the param would read (upon being submitted):

<param name="uploadURL" value="http://www.url.com/page.asp?variable=2">

<SELECT>
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
</SELECT>
 
<param name="uploadURL" value="http://www.url.com/page.asp?variable=">

Open in new window

0
bbdesign
Asked:
bbdesign
  • 5
  • 3
  • 3
2 Solutions
 
hieloCommented:
try:
<script>
function process(sel)
{
 var p = document.getElementById("uploadURL"); 
  p.value = p.value.replace(/variable=.*/,"variable=" + sel.value);
}
</script>
<SELECT onchange="process(this)">
<OPTION VALUE="1">1
<OPTION VALUE="2">2
<OPTION VALUE="3">3
</SELECT> 
<param id="uploadURL" name="uploadURL" value="http://www.url.com/page.asp?variable=">

Open in new window

0
 
bbdesignAuthor Commented:
The code looks good, but it isn't quite working, at least the way I've implemented it. See attached, this is almost exactly the code I'm using (just substituted out the URL). Maybe there is a typo or just a small thing that isn't assigning it correctly? If I make a selection from the menu and then view the source code, should I be able to see the value inserted?

<SCRIPT LANGUAGE="JavaScript"><!-- Hide from old browsers
	function processurl(sel) {
		var p = document.getElementById("uploadURL");
		p.value = p.value.replace(/Country=.*/,"Country=" + sel.value);
	}
// Stop hiding from old browsers -->
</SCRIPT>
 
<DIV CLASS="body">Upload files to: <SELECT ONCHANGE="processurl(this)">
<OPTION VALUE="-Master Files">Master Files<OPTION VALUE="Italy">Italy<OPTION VALUE="Sweden">Sweden<OPTION VALUE="United States">United States
	</SELECT></DIV>
 
<DIV><applet name="uploadApplet" code="javaatwork.myuploader.UploadApplet.class" archive="myuploader-standard-signed-1.11.jar, labels.jar" width="400" height="250">
	<param id="uploadURL" name="uploadURL" value="https://url.com/upload.asp?Country=">
	<param id="successURL" name="successURL" value="https://url.com/distributors.asp?menuselect=fileuploads">
</applet></DIV>

Open in new window

0
 
ASPSQLServerCOMCommented:
hi,
no you can not see the value appended
if you want to see then after the
p.value = p.value.replace(/Country=.*/,"Country=" + sel.value);


use alert(p.value); then it will dispaly that it has appeneded the value
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!

 
hieloCommented:
that seems to work right. The only other thing that comes to mind is to encode the values:
<SCRIPT LANGUAGE="JavaScript"><!-- Hide from old browsers
	function processurl(sel) {
		var p = document.getElementById("uploadURL");
		p.value = p.value.replace(/Country=.*/,"Country=" + encodeURIComponent(sel.value) );
		//this is to show the new value of the param
		alert(p.value);
	}
// Stop hiding from old browsers -->
</SCRIPT>
 
<DIV CLASS="body">Upload files to: <SELECT ONCHANGE="processurl(this)">
<OPTION VALUE="-Master Files">Master Files</OPTION><OPTION VALUE="Italy">Italy</OPTION><OPTION VALUE="Sweden">Sweden<OPTION VALUE="United States">United States</OPTION>
	</SELECT></DIV>
 
<DIV><applet name="uploadApplet" code="javaatwork.myuploader.UploadApplet.class" archive="myuploader-standard-signed-1.11.jar, labels.jar" width="400" height="250">
	<param id="uploadURL" name="uploadURL" value="https://url.com/upload.asp?Country=">
	<param id="successURL" name="successURL" value="https://url.com/distributors.asp?menuselect=fileuploads">
</applet></DIV>

Open in new window

0
 
bbdesignAuthor Commented:
OK, I can confirm that the script is receiving and applying the value, however its not "taking" on the element itself. Is there anything in the attached Applet code that would be preventing the script from not communicating properly with it? When I click the "submit" on the Applet, it isn't taking the modified URL along with it for some reason. It seems like I'm really close to a solution here, thanks for your help.
<DIV><applet name="uploadApplet" code="javaatwork.myuploader.UploadApplet.class" archive="myuploader-standard-signed-1.11.jar, labels.jar" width="400" height="250">
	<param id="uploadURL" name="uploadURL" value="https://url.com/upload.asp?Country=">
	<param id="successURL" name="successURL" value="https://url.com/distributors.asp?menuselect=fileuploads">
</applet></DIV>

Open in new window

0
 
bbdesignAuthor Commented:
I tried both of those suggestions, no luck unfortunately.
0
 
ASPSQLServerCOMCommented:
hi, did you tried the
function processurl(sel) {
alert(sel.value);
            var p = document.getElementById("uploadURL");
            p.value = p.value.replace(/Country=.*/,"Country=" + encodeURIComponent(sel.value) );
            alert(p.value);
      }

also instead of <param .... could it be possible  to pass the value in
><applet name="uploadApplet" uploadURL..........
I am not good with applet, but its suggestion
0
 
bbdesignAuthor Commented:
I added in the 2nd alert. I can confirm that the exact values that I want are popping up in the alerts. So it appears that for some reason the values in the alerts just aren't making it to the element for some reason.

The URL is stored in the <PARAM> tag, not in the <APPLET>, so I don't think that would work.

I wonder if the problem is because of the applet, maybe its ignoring the value that is assigned to it after it has already been loaded. If that's the case, I'll have to write to javaatwork.com tech support and see if they have a workaround.
0
 
ASPSQLServerCOMCommented:
other option is like on select change you can submit the page on server and on server you can assign the value to applet, and then when it comes to browser it wil have the URL value
0
 
hieloCommented:
>>When I click the "submit" on the Applet, it isn't taking the modified URL along with it for some reason
I never done any applets, so I don't know what's the expected behaviour - meaning, I don't know if it is supposed to scan the DOM and get the current values of the param as it is in the DOM OR if it is supposed to pass the value that it gor originally from the server. Again, I'm not familiar with applets.
0
 
bbdesignAuthor Commented:
That works! I modified the script to reload the page instead of modifying the value on the fly. I guess the Applet isn't accepting changes to the DOM since it was already loaded.

Anyway, thanks both for your help. hielo for the script and ASPSQLServerCOM for the idea of reloading the page.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now