1

The original URL is http://mysite.com/locations.aspx When someone clicks on Locations link somewhere and come to this page, on page load, i want the URl to appended as follows on the fly? The Hospital is a checkbox on the page which needs to be checked by default. So when they land on the page, they see all the hospitals instead of having to check the hospital check box and reload the page. Is this possible using jquery?

http://mysite.com/locations.aspx?k=("Hospital")

Find locations by&#160;<input name="Keyword" type="text" size="70"/><input name="Search" type="submit" value="Search"/><br/><br/>

Hospitals<input name="Hospitals" type="checkbox" value="Hospital"/> &#160; 
Offices<input name="Office" type="checkbox" value="Office"/> &#160; 
Emergency Centers<input name="EmergencyCenters" type="checkbox" value="Emergency"/>&#160; 
Out-Patient Centers<input name="Out-Patient" type="checkbox" value="Out-Patient"/>&#160; 
Facilities<input name="Facility" type="checkbox" value="Facility"/>
Anjana Sharma
  • 3,595
  • 5
  • 34
  • 50
  • I understand I can have the HREF value of "Locations" link as http://mysite.com/locations.aspx?k=("Hospital") and have the hospitals checked = true.. I wonder if there is any other ways? – Anjana Sharma Feb 24 '12 at 20:43

2 Answers2

3

You could create (inside the page http://mysite.com/locations.aspx ) a function like:

function getDefault() {
var trail = '?k=("Hospital")';
var url = "http://mysite.com/locations.aspx" + trail;
window.location = url;
}

and add onload to the <body> tag like

<body onload="getDefault();">

of course, it will reload the page (without user intervention) but with the new trailing parameter.

... as for the check box, you can add the proper attribute

$(document).ready(function() {
$("input[name=Hospitals]").attr('checked','checked');
}); //  ready

and it will be checked on the fly.

JFK
  • 40,294
  • 31
  • 126
  • 295
0

In newer browsers you can use the HTML5 history api to change the url without a page reload, however, older browsers that don't support it will require a page reload.

Community
  • 1
  • 1
Kevin B
  • 92,700
  • 15
  • 158
  • 170