Link to home
Start Free TrialLog in
Avatar of Brad Bansner
Brad Bansner

asked on

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

Avatar of hielo
hielo
Flag of Wallis and Futuna image

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

Avatar of Brad Bansner
Brad Bansner

ASKER

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

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
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

I tried both of those suggestions, no luck unfortunately.
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
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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.
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.