Value radiobutton
Добрый день!
Есть 3 параметра, длина, ширина, глубина в итоге у нас есть определенное количество выборок типа "длина, ширина, глубина" и нужно, чтобы каждая из них переадресовывала на свою страницу Форму я написал. теперь загвоздка в том, как мне получить выбранное значение радиобаттона, помогите, плиз, очень надо <html> <head> <script> function validate() { var width = getElementByName('width').value; var height = getElementByName('height').value; var glubina = getElementByName('glubina').value; if ( (width == '902') && (height == '2070') && (glubina == '450') ) { window.location.href = "www.yandex.ru"; return false; } return true; } </script> </head> <body> <table style="width: 980px; height: 532px; background-image: url('http://site.ideasar.ru/images/raz.png');" border="0"> <tbody> <tr> <td valign="top"> <div style="text-align: center; margin: 10px 0;"><span style="margin-left: 10px; color: #571f00; font-size: 18px; font-family: Arial;">ВЫБЕРИТЕ РАЗМЕР ШКАФА</span></div> <div style="height: 470px; margin: 0 15px;"> <div style="padding: 35px;"> <table style="width: 860px; height: 400px;" cellspacing="40" cellpadding="40"> <tbody> <tr> <td> <form method="POST" id="form_id" onsubmit="return validate();"> <input type="radio" name="width" id="1" value="902"> 902 <input type="radio" name="width" id="1" value="1188">1188 <input type="radio" name="width" id="1" value="1488">1488 <input type="radio" name="width" id="1" value="1774">1774 <input type="radio" name="width" id="1" value="2074">2074 <input type="radio" name="width" id="1" value="2360">2360 <br> <input type="radio" name="height" value="2070"> 2070 <input type="radio" name="height" value="2400">2400 <br> <input type="radio" name="glubina" value="450"> 450 <input type="radio" name="glubina" value="600">600 <br> <input type="submit" value="Далее" /></form> </td> </tr> </tbody> </table> </div> </div> </td> </tr> </tbody> </table> </body> </html> |
Antond,
var width = document.getElementsByName('width'); var height = document.getElementsByName('height'); var glubina = document.getElementsByName('glubina'); for (i=0; i < width.length; i++) { if (width[i].checked) { width = width[i].value; break; } } for (i=0; i < heigth.length; i++) { if (height[i].checked) { height = height[i].value; break; } } for (i=0; i < glubina.length; i++) { if (glubina[i].checked) { glubina = glubina[i].value; break; } } |
Цитата:
|
Неужели никто не подскажет?!
Неужели никто не подскажет, я уже все форумы перерыл, ничего не работает...
|
Antond,
<html> <head> <script> function validate() { var width = document.getElementsByName('width'); var height = document.getElementsByName('height'); var glubina = document.getElementsByName('glubina'); for (i=0; i < width.length; i++) { if (width[i].checked) { width = width[i].value; break; } } for (i=0; i < height.length; i++) { if (height[i].checked) { height = height[i].value; break; } } for (i=0; i < glubina.length; i++) { if (glubina[i].checked) { glubina = glubina[i].value; break; } } if ( (width == '902') && (height == '2070') && (glubina == '450') ) { window.location.href = "http://www.yandex.ru"; return false; } //return true; } </script> </head> <body> <form method="POST" action="http://www.google.ru" id="form_id" onsubmit="return validate();"> <input type="radio" name="width" id="1" value="902"> 902 <input type="radio" name="width" id="1" value="1188">1188 <input type="radio" name="width" id="1" value="1488">1488 <input type="radio" name="width" id="1" value="1774">1774 <input type="radio" name="width" id="1" value="2074">2074 <input type="radio" name="width" id="1" value="2360">2360 <br> <input type="radio" name="height" value="2070"> 2070 <input type="radio" name="height" value="2400">2400 <br> <input type="radio" name="glubina" value="450"> 450 <input type="radio" name="glubina" value="600">600 <br> <input type="submit" value="Далее" /></form> </body> </html> |
Цитата:
<!DOCTYPE html> <html> <head> <!-- <script src="http://code.jquery.com/jquery-latest.js"></script> <link rel="stylesheet" type="text/css" href="tmp.css" /> --> <style type="text/css"> </style> <script type="text/javascript"> /* Тут описать все наборы и ссылки */ var ourl={ '902x2070x450':'http://www.yandex.ru', '1188x2400x600':'http://javascript.ru/forum/dom-window/32227-value-radiobutton.html' }; function validate() { var of=document.getElementById('form_id'); var oi=of.getElementsByTagName('input'); var o={}; var i; for (i=0; i<oi.length; i++) { if (oi[i].checked) { o[oi[i].name]=oi[i].value; }; }; var str=o.width+'x'+o.height+'x'+o.glubina; if (ourl[str]==undefined) { alert('Плохой размер...'); return false; }; of.action=ourl[str]; return true; }; </script> </head> <body> <table style="width: 980px; height: 532px; background-image: url('http://site.ideasar.ru/images/raz.png');" border="0"> <tbody> <tr> <td valign="top"> <div style="text-align: center; margin: 10px 0;"><span style="margin-left: 10px; color: #571f00; font-size: 18px; font-family: Arial;">ВЫБЕРИТЕ РАЗМЕР ШКАФА</span></div> <div style="height: 470px; margin: 0 15px;"> <div style="padding: 35px;"> <table style="width: 860px; height: 400px;" cellspacing="40" cellpadding="40"> <tbody> <tr> <td> <form method="POST" id="form_id" onsubmit="return validate();"> <input type="radio" name="width" id="1" value="902">902 <input type="radio" name="width" id="1" value="1188">1188 <input type="radio" name="width" id="1" value="1488">1488 <input type="radio" name="width" id="1" value="1774">1774 <input type="radio" name="width" id="1" value="2074">2074 <input type="radio" name="width" id="1" value="2360">2360 <br> <input type="radio" name="height" value="2070">2070 <input type="radio" name="height" value="2400">2400 <br> <input type="radio" name="glubina" value="450">450 <input type="radio" name="glubina" value="600">600 <br> <input type="submit" value="Далее" /> </form> </td> </tr> </tbody> </table> </div> </div> </td> </tr> </tbody> </table> </body> </html> |
Часовой пояс GMT +3, время: 04:28. |