Radio Buttons JS Code

Status
Not open for further replies.

Patrick.Kershner

Solid State Member
Messages
9
Location
Colorado Springs
Hello everyone,

I am tring to do a simple selection using radio buttons and have what they select open up in an iframe: Here is what i have so far (I am not that fluent with JS yet) .

<form name="priceForm" target="lvlframe" method="post">
<input type="radio" value="business" name="pricelvl" onclick="document.open()" />Business<br />
<input type="radio" value="residential" name="pricelvl" onclick="document.open()"/>Residential<br />
</form>
<iframe name="lvlframe" height="50%" width="50%"></iframe>

But i know that i need a Javascript at the top of the page so when they click on Business it opens the right webpage.
If you can help please let me know!

Thanks,
Patrick Kershner
 
Code:
<form name="priceForm" target="lvlframe" method="post">
<input type="radio" value="business" name="pricelvl" onclick="changeFrame('lvlframe','business.html');" />Business<br />
<input type="radio" value="residential" name="pricelvl" onclick="changeFrame('lvlframe','residential.html');"/>Residential<br />
</form>
<iframe id="lvlframe" name="lvlframe" height="50%" width="50%"></iframe>

Place this in your <head> :

Code:
<script type="text/javascript">

function changeFrame(id,page) {
	var el = document.getElementById(id); // target the iframe element
 
	var url = "http://your-site.com/"; // put the url of your site

	el.src = url+page; // change the iframe src to the new page
}
</script>


All you need to change is the page names on the form ("business.html","residential.html") and put the name of your site (don't forget a trailing slash) into the JS function.
 
Awesome, Thanks it works, The only thing tho is i dont have the site online yet so no url for the choices. I have it on a test server for dreamweaver. But as far as i can see its working nicely! Thanks again
 
Status
Not open for further replies.
Back
Top Bottom