2

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"/>
1
  • I understand I can have the HREF value of "Locations" link as mysite.com/locations.aspx?k=("Hospital") and have the hospitals checked = true.. I wonder if there is any other ways? Commented Feb 24, 2012 at 20:43

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.