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

Brad BansnerWeb DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Brad BansnerWeb DeveloperAuthor 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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Brad BansnerWeb DeveloperAuthor 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
Brad BansnerWeb DeveloperAuthor 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
Brad BansnerWeb DeveloperAuthor 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
Brad BansnerWeb DeveloperAuthor 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.