-1

我有一个 HTML 页面,其中包含单选按钮、组合框、文本字段和一个搜索按钮。我想当我在文本字段中输入文本然后选择一个单选按钮和组合框时,当我单击搜索按钮时,数据库的结果将基于此值显示:单选按钮的值 + 组合框的值 + 的值文本字段。我希望这些值作为 Ajax 执行的 ShowResult(str) 函数的参数。我的代码是:

function ShowResult(str)
{
if (str=="")
  {
  document.getElementById("Div1").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("div1").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getresult.asp?q="+str,true);
xmlhttp.send();
}
</script>
<html>
<head>
    <title>Untitled Page</title>
</head>
<body>
<form>
<input id="Text1" type="text" />
<input id="Button1" type="button" value="Search" onclick="ShowResult(str)" /><br />
 <select name="combox" >
 <option value="Des">Descending</option>
 <option value="Ase">Ascending</option>
 </select><br />
<input type="radio" name="group1" value="Added_date"/> Added_date<br/>
<input type="radio" name="group1" value="Price"/>      Price<br /> 
<input type="radio" name="group1" value="Name"/>       Name<br/>
   </form>

   <div id="Div1" ></div>
</body>
</html>

但我不知道这些值是如何传递给 ShowResult(str) 的???请帮我。

4

1 回答 1

0
try this may help u it.
<script>
    function ShowResult() {
      var txtsearch=$("#Text1").val();
      var value =combox.options[combox.selectedIndex].value
      var radios = document.getElementsByName("group1");

    for (var i = 0; i < radios.length; i++) {       
        if (radios[i].checked) {
            alert(radios[i].value);
            var radioval=radios[i].value;
            break;
           }
         }
     var param="SearchText:"txtsearch,"Combo boxvalue:"value ,"radiobuttonvalue:"radios ;
      $.ajax({
            type: "POST",
            url: your servive url
            data: param,
            contentType: 'application/json',
            async: false,
            dataType: 'json',
            success: function (response) {

            },
            error: function (ErrorResponse) {



            }
        });
    }
</script>
<form>
<input id="Text1" type="text" />     
<input id="Button1" type="button" value="Search" onclick="ShowResult" />
<select name="combox" >
 <option value="Des">Descending</option>
 <option value="Ase">Ascending</option>
 </select><br />

<input type="radio" name="group1" value="Added_date"/> Added_date<br/>
<input type="radio" name="group1" value="Price"/>      Price<br /> 
<input type="radio" name="group1" value="Name"/>       Name<br/>
</form>
于 2013-02-02T09:17:21.623 回答