PDA

View Full Version : درخواست کد ساده جاوا اسکریپت



amku2010
جمعه 23 اردیبهشت 1390, 16:14 عصر
با درود
من یک کد جاوا اسکریپت رو می خوام بنویسم که از بین 4 گزینه گزینه صحیح رو که انتخاب کنیم پیغام بده که " گزینه صحیح انتخاب شد "
کد زیر رو نوشتم اما همش alret اول رو چاپ می کنه و وقتی یک radio رو انتخاب می کنم و بعدش یکی دیگه رو انتخاب می کنم هر دو radio رو بصورت انتخاب شده نشون میده
لطفا کمک کنید.





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select True Answer</title>
<script language="javascript" type="text/javascript">
function showTrue(){

if(document.getElementById("false").checked){
alert("Your Select is True");

}else{
alert("Your Select is not True");
}
}
</script>
</head>

<body dir="rtl">
<form id="form1" name="form1" method="post" action="" dir="rtl">
Select True Answer
<table width="200" border="1">
<tr>
<td colspan="2">Select False</td>
</tr>
<tr>
<td>Linux is Operating System</td>
<td><input name="radio1" type="radio" class="true" id="true" value="Choice a" /></td>
</tr>
<tr>
<td>Linux is Closed Operating System</td>
<td><input name="radio2" type="radio" class="false" id="false" value="Choice b" /></td>
</tr>
<tr>
<td>Linux is Name of Free Kernel Create by Linus Torvalds </td>
<td><input name="radio3" type="radio" class="true" id="true" value="Choice c" /></td>
</tr>
<tr>
<td>Linux refers to the family of Unix-like computer operating systems </td>
<td><input name="radio4" type="radio" class="true" id="true" value="Choice d" /></td>
</tr>
<td colspan="2"><input name="entekhab" type="button" class="entekhab" id="entekhab" value="انتخاب گزینه درست" onclick="showTrue()"/></td>
</tr>
</table>

</form>
</body>
</html>

Mr FTHEL
جمعه 23 اردیبهشت 1390, 16:34 عصر
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Select True Answer</title>
<script language="javascript" type="text/javascript">
function showTrue(){

if(document.getElementById("false").checked){
alert("Your Select is True");

}else{
alert("Your Select is not True");
}
}
</script>
</head>

<body dir="rtl">
<form id="form1" name="form1" method="post" action="" dir="rtl">
Select True Answer
<table width="200" border="1">
<tr>
<td colspan="2">Select False</td>
</tr>
<tr>
<td>Linux is Operating System</td>
<td><input name="radio" type="radio" class="true" id="true" value="Choice a" /></td>
</tr>
<tr>
<td>Linux is Closed Operating System</td>
<td><input name="radio" type="radio" class="false" id="false" value="Choice b" /></td>
</tr>
<tr>
<td>Linux is Name of Free Kernel Create by Linus Torvalds </td>
<td><input name="radio" type="radio" class="true" id="true" value="Choice c" /></td>
</tr>
<tr>
<td>Linux refers to the family of Unix-like computer operating systems </td>
<td><input name="radio" type="radio" class="true" id="true" value="Choice d" /></td>
</tr>
<td colspan="2"><input name="entekhab" type="button" class="entekhab" id="entekhab" value="?????? ????? ????" onclick="showTrue()"/></td>
</tr>
</table>

</form>
</body>
</html>

amku2010
جمعه 23 اردیبهشت 1390, 17:30 عصر
با سپاس از پاسختون Mr FTHEL
اما میشه بپرسم کجاش رو تغییر دادید یا اصلا تغییر ندادید

Mr FTHEL
جمعه 23 اردیبهشت 1390, 21:32 عصر
name="radio"
همش یک اسم گذاشتم به جای 1 2 3 ;)