webforms - javascript window redirect doesn't fire up -
this problem seems odd me , can't seem fix it. have simple html form; inside, have textbox , button shown down here:
<form id="form1" method="get"> <!-- note: no action property --> <div> <h1> simple test form</h1> <table border="0" width="400"> <tr> <td align="right"> of these words </td> <td> <input name="txtall" id="txtall" type="text" value="testing keyword" /> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="submit" onclick="myjs(this);" /> </td> </tr> </table> </div> </form>
myjs file as:
<script type="text/javascript"> function myjs(which) { var constant_site_target = "http://servername/redirect/target.aspx?text="; //capture values form var allwords = document.getelementbyid("txtall").value; var morestring = ""; //more data manipulation here..... var url = constant_site_target + allwords + morestring; window.open(url); //window.location = url; //doesn't work //window.location.href = url; //doesn't work //self.location = url; //doesn't work //top.location = url; //doesn't work } </script>
as can see, doesn't redirect designated url in javascript. when use window.open works. note in < form... > tag, don't put action property in it. don't want open new browser, redirect new url within same browser.
is there way redirect it?
here
function myjs(which) { var constant_site_target = "http://servername/redirect/target.aspx?text="; //capture values form var allwords = which.txtall.value; var morestring = ""; //more data manipulation here..... return constant_site_target + allwords + morestring; } <form id="form1" method="get" onsubmit="this.action=myjs(this)"> <div> <h1> simple test form</h1> <table border="0" width="400"> <tr> <td align="right"> of these words </td> <td> <input name="txtall" id="txtall" type="text" value="testing keyword" /> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="submit" value="submit" /> </td> </tr> </table> </div> </form>
to elaborate on comment:
<script> window.onload=function() { document.getelementbyid("submit").onclick=function() { var constant_site_target = "http://servername/redirect/target.aspx?text="; //capture values form var allwords = document.getelementbyid("txtall".value; var morestring = ""; //more data manipulation here..... location = constant_site_target + allwords + morestring; } } </script> <div> <h1> simple test form</h1> <table border="0" width="400"> <tr> <td align="right"> of these words </td> <td> <input name="txtall" id="txtall" type="text" value="testing keyword" /> </td> </tr> <tr> <td colspan="2" align="center"> <input type="button" id="submit" value="submit" /> </td> </tr> </table> </div>
Comments
Post a Comment