2013-03-04 41 views
0

嗨我需要創建一個表單有兩個單選按鈕是和否提交按鈕,如果用戶不選擇任何選項警報應彈出說'請選擇一個選項',如果是的,並提交按鈕一個jQuery的對話框應該彈出與對話框中的兩個按鈕確定和取消 - >如果用戶點擊確定,然後它應該去不同的頁面,如果沒有單選按鈕,並提交按鈕,那麼對話框應該彈出相同的好和取消按鈕,如果確定,那麼它應該去另一個頁面。我創建了這樣的事情,但不能夠給選定的單選按鈕使用jquery dialogbox的兩個單選按鈕的形式

<form action="" method="get" name="radval"> 
<table width="100"> 
<tr> 
<td width="41"><input name="xyz" type="radio" id="yes_chk" value="" required> 
    Yes</td> 
<td width="47"><input name="xyz" type="radio" id="yes_chk" value="" required> 
    No</td> 

</tr> 
<tr> 
<td colspan="4"><input type="submit" value="Submit" id="button"></td> 
</tr> 
</table></form> 

的JavaScript

<script src="js/jquery.reveal.js"></script> 
<script type="text/javascript"> 
    $(document).ready(function() { 

     $('#button').click(function(e) { // Button which will activate our modal 
      $('#modal').reveal({ // The item which will be opened with reveal 
       animation: 'fade',     // fade, fadeAndPop, none 
       animationspeed: 600,      // how fast animtions are 
       closeonbackgroundclick: true,    // if you click background will modal close? 
       dismissmodalclass: 'close' // the class of a button or element that will close an open modal 
      }); 
     return false; 
     }); 
    }); 
</script> 

如何根據所選擇的單選按鈕我重定向頁面。我是jquery的新手,有什麼幫助?

在此先感謝。

+0

ü可以創建一個鏈接 – PSR 2013-03-04 08:32:38

+0

不知道如何創建鏈接 – sailaja 2013-03-04 08:50:09

回答

0

我重建了一點,並在評論中可以看出U代碼解釋:

你的HTML有點調整

<form action="" method="get" name="radval" data-sjaak-module="sjaak.mod.form"> 
     <input name="yes-no" type="radio" class="yes_chk" value="yes">Yes 
     <input name="yes-no" type="radio" class="no_chk" value="no">No 
     <input type="submit" value="submit" id="button"> 
</form> 
 
$('#button').click(function(e) { // Button which will activate our modal 

e.preventDefault(); // prevent submitting and go trough the list below 
      var x = !$('.yes_chk').is(':checked'), // declaring variables it checks for the class yes_chk if it isn't checked 
       y = !$('.no_chk').is(':checked') 
      if (x && y) { // the condition if both fields are unchecked 
       alert('Make a choice'); // alert box that pops up if there is no choice made 
      } else if (x) { // if just x is not checked 
       var no = confirm('you checked no'); // putting it in a variable to use it in a later if 
       if(no == true) { // if clicked on ok do the following 
        parent.location='http://www.stackoverflow.com/'; 
       } else { // if clicked on cancel what to do 
        console.log('false'); 
        parent.location='http://stackoverflow.com/questions/15197403/form-with-two-radio-buttons-using-jquery-dialogbox'; 
       } 

      } else { 
       var yes = confirm('you checked yes'); 
       if(yes == true) { // if condition is met than 
        parent.location='http://www.stackoverflow.com/'; // go to this website 
       } else { // if cancel is pressed do the following 
        parent.location='http://stackoverflow.com/questions/15197403/form-with-two-radio-buttons-using-jquery-dialogbox'; 
       } 
      } 


// your code just below 
$('#modal').reveal({ // The item which will be opened with reveal 
animation: 'fade', // fade, fadeAndPop, none 
animationspeed: 600, // how fast animtions are 
closeonbackgroundclick: true, // if you click background will modal close? 
dismissmodalclass: 'close' // the class of a button or element that will close an open modal 
      }); 
     return false; 
     }); 
+0

感謝您的幫助!有用。 – sailaja 2013-03-05 01:24:08

+0

歡迎你Sailaja – 2013-03-05 07:57:38

+0

如果我添加我的jquery對話框代碼//你的代碼正好低於 $('#modal')。reveal({//將顯示的項目將被打開 animation:'fade',// fadeAndPop,none animationspeed:600,//動作速度有多快 closeonbackgroundclick:true,//如果你點擊背景將模態關閉? dismissmodalclass:'close'//關閉一個按鈕或元素的類打開模式 }); jquery對話框不是爲我而來....我如何使用jquery dialogbox?任何想法? – sailaja 2013-03-06 06:09:18