tags:

views:

501

answers:

1

I'm trying to load page content into a div via Ajax when a select option is selected

eg. I have a select box with 2 options the values are test.HTML and test1.HTML and under that I have a div and want the content from test.HTML and test1.HTML to load in the div when the select box changes... Via Ajax any suggestions?

Thanks

+4  A: 

Sure, that can be rather simple:

$("#mySelect").change(function(){
  $("#myDiv").load( $(this).val() );
});
<select id="mySelect">
  <option>test.html</option>
  <option>test1.html</option>
</select>

<div id="myDiv"></div>
Jonathan Sampson
you are missing ready event for the newbie +1 anyways :)
Sarfraz
I'm giving him the benefit of the doubt :)
Jonathan Sampson
good point, Jonathan
Darmen
Newbie here doesn't mean newbie!!! Thanks I'll give it a shot.
loo
One more thing, when the page loads it should load the selected option (eg the 3rd option is sel on p load) content
loo
You can cause it to auto-fire by calling the change method immediately after: `$("#mySelect").change(function(){...}).change();`
Jonathan Sampson
thanks for the reply.. can you please give me a exact code for the on page load eg. load mypage.html when the page loads,thanks
loo