It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming HTML Forum

Radio button with select list

Radio button with select list

Postby maruuma on Mon Oct 20, 2008 1:41 pm

I need a help in this code: i want when I select from the select list go direct to site that I choose.

for example when I choose yahoo i have to go directly to yahoo website.

Can any one help me plz.
<script>
function setList(theList) {
switch (theList) {
case 1 : {
document.theForm.mySelect.options[0].value="yahoo";
document.theForm.mySelect.options[1].value="msn";
document.theForm.mySelect.options[2].value="skype";
document.theForm.mySelect.options[3].value="";
document.theForm.mySelect.options[4].value="";
document.theForm.mySelect.options[5].value="";
document.theForm.mySelect.options[6].value="";
document.theForm.mySelect.options[7].value="";
document.theForm.mySelect.options[0].selected=true;
document.theForm.radioButton[0].checked=true;
break;
}
case 2 : {
document.theForm.mySelect.options[0].value="elaph";
document.theForm.mySelect.options[1].value="cnn";
document.theForm.mySelect.options[2].value="bbc";
document.theForm.mySelect.options[3].value="";
document.theForm.mySelect.options[4].value="";
document.theForm.mySelect.options[5].value="";
document.theForm.mySelect.options[6].value="";
document.theForm.mySelect.options[7].value="";
document.theForm.mySelect.options[0].selected=true;
document.theForm.radioButton[1].checked=true;
break;
}


}


setOptionText();
}

function setOptionText() {
document.theForm.mySelect.options[0].text=document.theForm.mySelect.options[0].value;
document.theForm.mySelect.options[1].text=document.theForm.mySelect.options[1].value;
document.theForm.mySelect.options[2].text=document.theForm.mySelect.options[2].value;
document.theForm.mySelect.options[3].text=document.theForm.mySelect.options[3].value;
document.theForm.mySelect.options[4].text=document.theForm.mySelect.options[4].value;
document.theForm.mySelect.options[5].text=document.theForm.mySelect.options[5].value;
document.theForm.mySelect.options[6].text=document.theForm.mySelect.options[6].value;
document.theForm.mySelect.options[7].text=document.theForm.mySelect.options[7].value;
}


</script>

</head>
<body onload="setList(1)">
<form name="theForm" onreset="setList(1)">
Sites<br>
<input checked name="radioButton" type="radio" value="Brgy" onclick="setList(1)">messanger
<input name="radioButton" type="radio" value="MuniCity" onclick="setList(2)">news
<hr size="1">
</select>
<select name="mySelect" style="width:250px;">
<option value="yahoo" selected>yahoo</option>
<option value="msn">msn</option>
<option value="skype">skype</option>
<option value="elaph">elaph</option>
<option value="cnn">cnn</option>
<option value=""></option>
<option value=""></option>
<option value=""></option>
</select>
<br><br>
</form>
maruuma
 
Posts: 3
Joined: Mon Oct 20, 2008 1:11 pm

Postby rangana on Tue Oct 21, 2008 12:19 am

Change this part:
Code: Select all
<select name="mySelect" style="width:250px;">


to:
Code: Select all
<select name="mySelect" style="width:250px;" onchange="location.href='http://www.'+this.value+'.com'">
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby maruuma on Tue Oct 21, 2008 5:58 am

Thanks a lot for your reply, but can I ask a favor if you don't mind how can I open the link in new window?
maruuma
 
Posts: 3
Joined: Mon Oct 20, 2008 1:11 pm

Postby rangana on Tue Oct 21, 2008 11:12 am

Replace it with this instead:
Code: Select all
<select name="mySelect" style="width:250px;" onchange="window.open('http://www.'+this.value+'.com')">
User avatar
rangana
500+ Club
 
Posts: 935
Joined: Wed Feb 27, 2008 5:14 am
Location: Cebu City Philippines

Postby maruuma on Tue Oct 21, 2008 7:25 pm

Hi rangana;
Thank you in the beggining.
Iknow that I disturb you, but really you're very helpful. I have a small problem : if I want to put a sentence with space in values in case statment the function onchange dosn't work because the name of site havn't any space like "islam on line" it should be http://www.islamonline.com without space, I try to use trim function to remove the space but dosn't work.

Can I have a help again???
maruuma
 
Posts: 3
Joined: Mon Oct 20, 2008 1:11 pm


Who is online

Users browsing this forum: No registered users and 7 guests