javascript - Redirect to a page according to selected option from radio button through 'onclick' , without &

This is the code which is not working according to my requirement<head><script type="text

This is the code which is not working according to my requirement

<head>

<script type="text/javascript">

function test(){

if(document.form.choice.value='pc'){

window.open('pc.php','_self');

return true;

}

else if(document.form.choice.value='ps2'){

window.open('ps2.php','_self');

return true;

}

else if(document.form.choice.value='ps3'){

window.open('ps3.php','_self');

return true;

}

else if(document.form.choice.value='psp'){

window.open('psp.php','_self');

return true;

}

}

</script>

</head>

<body>

Games<br /><br />

<form name="form">ALL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="radio" onClick="test()" name="choice" value="pc">PC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="ps2">PS2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="ps3">PS3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="psp">PSP &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>

</body>

Also i want to know that how to display the field automatically just by selecting the selected field in Drop down list without 'submit'

<select name="genre">
        <option value="">--Select Genre and Click Go--</option>
        <option value="All">All</option>
        <option value="Action / Mission">Action / Mission</option>
        <option value="Arcade">Arcade</option>
        <option value="Racing">Racing</option>
        <option value="Sports">Sports</option>
        <option value="Kids">Kids</option>
        <option value="Strategy">Strategy</option>
        <option value="Adventure">Adventure</option>
      </select>

This is the code which is not working according to my requirement

<head>

<script type="text/javascript">

function test(){

if(document.form.choice.value='pc'){

window.open('pc.php','_self');

return true;

}

else if(document.form.choice.value='ps2'){

window.open('ps2.php','_self');

return true;

}

else if(document.form.choice.value='ps3'){

window.open('ps3.php','_self');

return true;

}

else if(document.form.choice.value='psp'){

window.open('psp.php','_self');

return true;

}

}

</script>

</head>

<body>

Games<br /><br />

<form name="form">ALL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="radio" onClick="test()" name="choice" value="pc">PC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="ps2">PS2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="ps3">PS3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onClick="test()" name="choice" value="psp">PSP &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>

</body>

Also i want to know that how to display the field automatically just by selecting the selected field in Drop down list without 'submit'

<select name="genre">
        <option value="">--Select Genre and Click Go--</option>
        <option value="All">All</option>
        <option value="Action / Mission">Action / Mission</option>
        <option value="Arcade">Arcade</option>
        <option value="Racing">Racing</option>
        <option value="Sports">Sports</option>
        <option value="Kids">Kids</option>
        <option value="Strategy">Strategy</option>
        <option value="Adventure">Adventure</option>
      </select>
Share Improve this question edited Sep 13, 2014 at 14:29 Sushant 1,4141 gold badge15 silver badges32 bronze badges asked Sep 13, 2014 at 14:18 PawanPawan 91 gold badge2 silver badges8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 1

Try this...

EDITED:

<head>
<script src="https://ajax.googleapis./ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
<script type="text/javascript">
 function idForm(){
   var selectvalue = $('input[name=choice]:checked', '#idForm').val();


if(selectvalue == "pc"){
window.open('http://www.google.','_self');
return true;
}
else if(selectvalue == "ps2"){
window.open('http://www.google.','_self');
return true;
}else if(selectvalue == 'ps3'){
window.open('http://www.google.','_self');
return true;
}else if(selectvalue == 'psp'){
window.open('http://www.google.','_self');
return true;
}
return false;
};


</script>
</head>
<body>
Games<br /><br />
<form id="idForm">ALL &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio" onclick="idForm()"  name="choice" value="pc"/>PC &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio"  onclick="idForm()" name="choice" value="ps2"/>PS2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio"  onclick="idForm()" name="choice" value="ps3"/>PS3 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="radio"  onclick="idForm()" name="choice" value="psp"/>PSP &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</form>
</body>

Jsfiddle link

You can get the value of the option by adding onchange event in the <select> tag.

<select name="genre" onchange="selectOption()">
            <option value="">--Select Genre and Click Go--</option>
            <option value="All">All</option>
            <option value="Action / Mission">Action / Mission</option>
            <option value="Arcade">Arcade</option>
            <option value="Racing">Racing</option>
            <option value="Sports">Sports</option>
            <option value="Kids">Kids</option>
            <option value="Strategy">Strategy</option>
            <option value="Adventure">Adventure</option>
          </select>

In your script add this

function selectOption(){
//each option value
var option=document.form.genre.value;
alert(option);


}

For redirecting you can use window.location in your test() method use this window.location=yourpage.php instead of this window.open('pc.php','_self')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745241000a4618182.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信