iam working on javascript and html to redirect page. from three textbox value using in url button is not working why?
code is here
<h3>Enter Reference Number</h3>
<td style="background-color:#f7faff;" width="300">
<input name="txtBatchNo" type="text" size="2" maxlength="2">
-
<input name="txtSubDiv" type="text" size="5" maxlength="5">
-
<input name="txtRefNo" type="text" size="8" maxlength="8">
</select></td>
<input type="button" onclick="openPage()" value="Check BiLL">
<script type="text/javascript">
function openPage() {
var add1 = document.getElementById('txtBatchNo').value;
var add2 = document.getElementById('txtSubDiv').value;
var add3 = document.getElementById('txtRefNo').value;
var url="http://www.lesco.gov.pk:36269/Default1.aspx?BatchNo=" + add1 + "&SubDiv=" + add2 + "&RefNo=" + add3 + "&RU=U&Exec=941N7";
//alert(url);
window.open(url,"_blank");
}
</script>```
Actually you have errors on variables add1, add2 and add3, you're trying to select those elements by Id but they do not have an Id, so your code breaks before opening the page. I fix it here:
<h3>Enter Reference Number</h3>
<td style="background-color:#f7faff;" width="300">
<input name="txtBatchNo" type="text" size="2" maxlength="2" id="txtBatchNo">
-
<input name="txtSubDiv" type="text" size="5" maxlength="5" id="txtSubDiv">
-
<input name="txtRefNo" type="text" size="8" maxlength="8" id="txtRefNo">
</select></td>
<input type="button" onclick="openPage()" value="Check BiLL">
<script type="text/javascript">
function openPage() {
var add1 = document.getElementById('txtBatchNo').value;
var add2 = document.getElementById('txtSubDiv').value;
var add3 = document.getElementById('txtRefNo').value;
var url="http://www.lesco.gov.pk:36269/Default1.aspx?BatchNo=" + add1 + "&SubDiv=" + add2 + "&RefNo=" + add3 + "&RU=U&Exec=941N7";
//alert(url);
window.open(url, "_blank");
}
</script>
Note that the page won't open here, because it will get blocked by the sandbox.