put onclick on submit button to call submitFunc() , rather than use form action:
<input type="button" onClick="submitFunc();" value="Pass Parameters"/>
js functions:
<script language="javascript" type="text/javascript">
function submitFunc()
{
loopRemove("text",3);
document.testform.action = "file:///C:/Users/mwafi/Desktop/test.html";
document.testform.submit();
}
function loopRemove(startName,count)
{
for(var i=1;i<=count;i++)
{
if(document.getElementById(startName+i).value=="")
{
var t = document.getElementById(startName+i);
t.parentNode.removeChild(t);
}
}
}
</script>
full code with HTML form:
<html>
<title>Pass non-empty parameters</title>
<head>
<script language="javascript" type="text/javascript">
function submitFunc()
{
loopRemove("text",3);
document.testform.action = "http://www.google.com/";
document.testform.submit();
}
function loopRemove(startName,count)
{
for(var i=1;i<=count;i++)
{
if(document.getElementById(startName+i).value=="")
{
var t = document.getElementById(startName+i);
t.parentNode.removeChild(t);
}
}
}
</script>
</head>
<body onload="document.testform.reset();">
<form name="testform">
<h3>Pass Non-empty parameters</h3>
Parameter 1 : <input type="text" name="text1" id="text1" /><br>
Parameter 2 : <input type="text" name="text2" id="text2" /><br>
Parameter 3 : <input type="text" name="text3" id="text3" /><br><br>
<input type="button" onClick="submitFunc();" value="Pass Parameters"/>
<form>
</body>
</html>
remember don't use form action.
source: http://www.scriptsplash.com/2009/07/passing-only-non-empty-fields-on-form.html