Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

linking to self + passing GET variables..

Status
Not open for further replies.

billycat

MIS
Apr 28, 2005
22
US
I have a form, when submitted, it passes GET variables back to self. If i then go ahead and select another form value, in the URL, the current GET values stay, and the new ones are appended to the URL.

Code:
<input type="button" value="submit" onClick="window.location=self.location.href + '?row=' + document.myform.mylist.value + '&value=' + this.form.values.value + '&set=1';">
the URL after one submit:
adv_search5.php?row=ip_address&value=20.7.254.33&set=1

the URL after two:
adv_search5.php?row=ip_address&value=20.7.254.33&set=1?row=app_server&value=Yes&set=1
 
Code:
<input type="button" value="submit" onClick="window.location=self.location.href[!].split("?")[0][/!] + '?row=' + document.myform.mylist.value + '&value=' + this.form.values.value + '&set=1';">

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
its not submitted at all, after i add the code as you wrote it.. im not good with JS, sorry.
 
You don't put anything inside the split, it should work exactly as I showed. Copy/paste this example into a new html file:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<title>title test</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<script type="text/javascript">

var a = "[URL unfurl="true"]http://www.somepage.com?abc=xyz";[/URL]
alert(a.split("?")[0]);

</script>
<style type="text/css"></style>
</head>
<body>
</body>
</html>

You'll see that the querystring results from the address stored in the variable a are dropped off the string. This allows you to add fresh, new querystring results to your link. If you made the changes I noted above then there's something else wrong with your code because what I posted should work.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
When i press submit, nothing at all is happening..
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<SCRIPT LANGUAGE="JavaScript">
function testResults (form) {
var TestVar = form.mylist.value;
window.open('select_options.php?row=' + TestVar , 'child_window' , 'toolbar=0, location=0, status=0, menubar=0, scrollbars=1, resizable=0, width=200, height=400');
}


window.name="somename"

 
</script>


</head>
<body>
<table bgcolor="#d0cece" cellspacing="3">
<tr>
<td valign=top>
<form name=myform><b><font size=2 face=arial>Field:&nbsp;&nbsp;&nbsp;&nbsp;</b><select name=mylist class=formfield><option value=app_server>app_server<option value=asset_tag>asset_tag<option value=backup_schedule>backup_schedule<option value=backup_server_name>backup_server_name<option value=cpus>cpus<option value=domain_name>domain_name<option value=drac_hostname>drac_hostname<option value=drac_ip>drac_ip<option value=drive_capacity>drive_capacity<option value=eav_ver>eav_ver<option value=firmware_bios_updates>firmware_bios_updates<option value=gis_supported>gis_supported<option value=ip_address>ip_address<option value=last_modified_by>last_modified_by<option value=maint_lease_expiration_date>maint_lease_expiration_date<option value=maintenance_contract>maintenance_contract<option value=maintenance_vendor>maintenance_vendor<option value=manufacturer>manufacturer<option value=model>model<option value=modified_date>modified_date<option value=monitored>monitored<option value=neteiss_path>neteiss_path<option value=number_of_nics>number_of_nics<option value=operational_support_hours>operational_support_hours<option value=primary_admin>primary_admin<option value=processor>processor<option value=region>region<option value=second_ip_address>second_ip_address<option value=secondary_admin>secondary_admin<option value=serial_number>serial_number<option value=server_alias_name>server_alias_name<option value=server_description>server_description<option value=server_location>server_location<option value=server_name>server_name<option value=server_os>server_os<option value=status>status<option value=team_lead>team_lead<option value=total_ram>total_ram<option value=uam>uam</select></td><td>
<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value:</b>
<INPUT TYPE="text" NAME="values" value=""  onClick=testResults(this.form)>


</td>
</tr>
</table>
<input type="button" value="submit" onClick="window.location=self.location.href.split("?")[0] + '?row=' + document.myform.mylist.value + '&value=' + this.form.values.value + '&set=1';"><input type="reset" value="reset">
	
</FORM>
</BODY>
</HTML>


 
My apologies, using double quotes in the split function to encapsulate the ? was what screwed it up, it terminated the onclick value for the button. Just change it to single quotes instead:
Code:
split([!]'[/!]?[!]'[/!])

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
uncle_rico_thumb.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top