Current location: Hot Scripts Forums » General Web Coding » JavaScript » using java and radio buttons to choose search. PLEASE HELP!!!


using java and radio buttons to choose search. PLEASE HELP!!!

Reply
  #1 (permalink)  
Old 03-12-06, 11:07 PM
shelydmb shelydmb is offline
New Member
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
using java and radio buttons to choose search. PLEASE HELP!!!

Hello I am trying to make a search choice similar to http://www.ohio.edu .

I am trying to use java script to do this. I want to use tadio buttons like they do. I have found how to do it using an option menu but not radio buttons. Can anyone help. I would so greatly appreciate it!! Thanks! I am more of a graphic designer then a programmer. I am gonna be taking programming classes soon to help me in my job but for now I am lost!

This is the code for the menu. I want that using radio buttons.

Code:
<script language="JavaScript">
<!--
function openDir(form) {
window.location =(form.dir.options[form.dir.selected Index].value);
}
// -->
</script>
</head>
<body>
<form name="myform">
<div align="center"><p><select name="dir" size="1">
<option value="">Choose a Site</option>
<option value="http://www.yahoo.com/">Yahoo!
<option value="http://www.excite.com/">Excite
</select><input type="button" name="button" value="Go!" onclick="openDir(this.form);"></p>
</div>
</form>
Reply With Quote
  #2 (permalink)  
Old 03-13-06, 03:19 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Since all radio buttons that belong together need to have the same name, you need to loop through a collection of them.

This can either be done by looping through form.dir[i] in your code, or by utilizing the documeng.getElementsByName method and loop through the returned collection.
Here's an example:
Code:
<html>
<head>
<script language="JavaScript">
<!--
function openDir(form) {
	var dirs=form.dir
	for(i=0;i<dirs.length;i++){
		if(dirs[i].checked){
			window.location = dirs[i].value;
			break;
		}
	}
}
// -->
</script>
</head>
<body>
<form name="myform">
<div align="center"><p>Yahoo <input type="radio" name="dir" value="http://www.yahoo.com/" checked><br>
Excite <input type="radio" name="dir" value="http://www.excite.com/"><br>
<input type="button" name="button" value="Go!" onclick="openDir(this.form);"></p>
</div>
</form> 
</body>
</html>
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 11:04 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.