开发者

Problem in javascript while submiting the form

Hi I am getting null value as i am submiting the form using javascript and passing the parameter using querystring ,I am using request.getParameter("name"), to get the result ,and also i am not getting any parameter in queryString(address bar).

Please help me ....Thnx...Please ...

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function checkempno()
{

    var empno=document.getElementById("empno");
    var empvalue=empno.value;
    alert(empvalue);
    if(empvalue=="")
    {
        alert("Employee Number is requried");
        empno.focus();
        return false;

    }

}
function checkempname()
{

    var empname=document.getElementById("empname");
    var empvalue=empname.value;
    if(empvalue==""||empvalue==null)
开发者_运维百科    {
        alert("Employee Empname is requried");
        empname.focus();
        return false;

    }

}

function calljsp(){
    var fform=document.forms["myform"];

    fform.action="result.jsp?name=jill&sex=f";
    alert(fform.action);    
    document.forms["myform"].method="GET";

    fform.submit();




}
</script>

</head>
<body>
<form  id="myform">
<div id="body">
<table style="border: 1px solid black;width:60%;padding:15px;margin-left: auto;margin-right: auto;">

<tr>
<td style="text-align: center"> <input type="submit" value="Save it" style="text-align: center" ></input>   </td>
<td > <input type="reset"   value="Referesh" > </td>
</tr>
<tr>
<td style="text-align:center;">&nbsp;&nbsp;Click this to submit the form using JScript</td>
  <td><input type="button" name="subjsript" size="30" onclick="calljsp();" value="Submit Via JScript"/></td>
</tr>
</table>
</form>
  </body>
</html>


Your current code requires the form to have name not id, so have such form tag:

<form  id="myform" name="myform">

To save yourself such trouble though, you can pass reference to the button when calling the function:

<input type="button" ... onclick="calljsp(this);" ...

Then have such function:

function calljsp(oButton) {
   var fform = oButton.form;
   fform.action = "result.jsp?name=jill&sex=f";
   ...

This way the name doesn't matter.


In your function calljsp()

use

  var fform = document.getElementById('myform');

instead of

 var fform=document.forms["myform"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜