Codeasearch.com - Search your code with us Login | Register | Contact us
  Forums > Javascript > window.location not working
thiyaghuck
Posted on Apr 28, 2009
Join Date: November 2008
Location: India ( chennai )
Posts: 14
 
window.location not working  

Hi,

Please find my html and javascript code. When i submit my form after validation i am redirecting to a php page. In this window.location not working. Can anyone fix this?

HTML:

<html>
<head>
<title>Mafiree :: Admin</title>
<link type="text/css" rel="stylesheet" href="css/stylesheet.css"></link>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script language="javascript" src="js/calander.js"></script>
<script language="javascript">


// - The new row function
var i=1;
function addRow(){

var tbody = document.getElementById("table1").tBodies[0];
var row = document.createElement("TR");
row.setAttribute("id","row"+i);
//alert (i);

var cell= document.createElement("TD");
cell.setAttribute("width","4%");
cell.setAttribute("valign","top");
cell.setAttribute("class","Text_10_Gray");
cell.innerHTML="BILLS :";

var cell11 = document.createElement("input");
cell11.setAttribute("type","radio");
cell11.setAttribute("name","reimb_bills" +i);
cell11.setAttribute("id","reimb_bills" +i);
cell11.setAttribute("checked", "checked");
cell11.setAttribute("value","available");

var cell11_td= document.createElement("TD");
cell11_td.setAttribute("width","6%");
cell11_td.setAttribute("valign","top");
cell11_td.setAttribute("class","Text_10_Gray");
cell11_td.innerHTML="Available<br>";
//cell11.setAttribute("checked");
//cell11.setAttribute("value", "1");
var cell111 = document.createElement("input");
cell111.setAttribute("type","radio");
cell111.setAttribute("name","reimb_bills" +i);
cell111.setAttribute("id","reimb_bills" +i);
cell111.setAttribute("value","unavailable");

var cell111_td= document.createElement("TD");
cell111_td.setAttribute("width","11%");
cell111_td.setAttribute("valign","top");
cell111_td.setAttribute("class","Text_10_Gray");
cell111_td.innerHTML="Unavailable";

var cell2_td= document.createElement("TD");
cell2_td.setAttribute("width","6%");
cell2_td.setAttribute("valign","top");
cell2_td.setAttribute("class","Text_10_Gray");
cell2_td.innerHTML="BILL DATE :";

var cell2 = document.createElement("input");
cell2.setAttribute("type","text");
cell2.setAttribute("name","reimb_date" +i);
cell2.setAttribute("id","reimb_date" +i);

var cell3_td= document.createElement("TD");
cell3_td.setAttribute("width","6%");
cell3_td.setAttribute("valign","top");
cell3_td.setAttribute("class","Text_10_Gray");
cell3_td.innerHTML="BILL NO :";

var cell3 = document.createElement("input");
cell3.setAttribute("type","text");
cell3.setAttribute("name","reimb_billno" +i);
cell3.setAttribute("id","reimb_billno" +i);

var cell4_td= document.createElement("TD");
cell4_td.setAttribute("width","9%");
cell4_td.setAttribute("valign","top");
cell4_td.setAttribute("class","Text_10_Gray");
cell4_td.innerHTML="DESCRIPTION :";

var cell4 = document.createElement("input");
cell4.setAttribute("type","text");
cell4.setAttribute("name","reimb_description" +i);
cell4.setAttribute("id","reimb_description" +i);
cell4.setAttribute("onKeyPress","reimb_active(id);");

var cnt=document.getElementById(`count`);
var count=cnt.value;
cnt.value++;
//alert("count"+count);
//var cell5 = document.createElement("input");
//cell5.setAttribute("type","hidden");
//cell5.setAttribute("name","count");
//cell5.setAttribute("id","count");
//cell5.setAttribute("value",""+i);


row.appendChild(cell);
row.appendChild(cell11);
row.appendChild(cell11_td);
row.appendChild(cell111);
row.appendChild(cell111_td);
row.appendChild(cell2_td);
row.appendChild(cell2);
row.appendChild(cell3_td);
row.appendChild(cell3);

row.appendChild(cell4_td);
row.appendChild(cell4);
//row.appendChild(cell5);
tbody.appendChild(row);
i++;
//alert("i= " +i);
//alert(row.innerHTML);
}
</script>
</head>
<body onLoad="addRow();addRow();addRow();addRow();addRow();addRow();reimb_deactive(i-1);">

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="left"><img src="images/logo.gif"></td>
</tr>

<tr>
<td><hr></td>
</tr>

<tr>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td><a href="index.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">HOME</a></td>
<td style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333; text-decoration:none; "><a href="add_users.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">ADD USERS</a></td>
<td style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333; text-decoration:none; "><a href="search_users.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">SEARCH USERS</a></td>
<td style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333; text-decoration:none; "><a href="change_password.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">CHANGE PASSWORD</a></td>
<td><a href="reimbustment.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">REIMBUSTMENT</a></td>
<td><a href="register_meet.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">BANGLORE MEET</a></td>
<td><a href="logout.php" style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px;color:#333333;">LOGOUT</a></td>
</tr>
</table>
</td>
</tr>

<tr>
<td><hr></td>
</tr>

</table>
<div id="cal" style="display:none;width:160px;position:absolute;"></div>
<table width="100%" border="0" cellpadding="0px" cellspacing="0px">
<tr>
<td>
<table width="95%" border="0" align="center" cellpadding="0" cellspacing="6" style="border:0.01em solid #666666 ">
<tr>
<td class="Text_10_Gray">SUBMIT REIMBUSTMENT</td>
<td><a href="reimbustment_viewall.php" class="Text_10_Gray">VIEW ALL FORMS (Admin)</a></td>
<td ><a href="reimbustment_userview.php" class="Text_10_Gray">VIEW MY FORM (Users)</a></td>
<td ><a href="#" class="Text_10_Gray" id="add_row" onclick="addRow();reimb_deactive_add();">ADD MORE FORM</a></td>
<!-- <td><input name="add_row" type="button" id="add_row" value="Add Row" onclick="addRow()" /></td> -->
</tr>
</table>
</td>
</tr>

<tr>
<td>&nbsp;</td>
</tr>


<tr>
<td>
<form name="reimbustment" action="#" method="post" onSubmit="return reimb_val();" >
<table width="95%" border="0" align="center" cellpadding="4" cellspacing="12" style="border:0.01em solid #666666 ">
<tr>
<td class="Text_Black" align="center"><u>REIMBUSTMENT FORM</u></td>
</tr>

<tr>
<td valign="top">
<table width="90%" id="table1" align="center">
<tr>
<td><input type="hidden" id="count" value="1"></td>
</tr>
</table>
</td>
</tr>

<tr>
<td align="center"><input type="submit" name="submit" class="Button" value="SUBMIT">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" class="Button" name="clear" value="CLEAR"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>

</body>
</html>


JAVASCRIPT:

function reimb_deactive(n){
for(i=2;i<=n;i++)
{
document.getElementById(`reimb_bills`+i).disabled=true;
document.getElementById(`reimb_date`+i).disabled=true;
document.getElementById(`reimb_billno`+i).disabled=true;
document.getElementById(`reimb_description`+i).disabled=true;
}
}

function reimb_deactive_add(){
n=document.getElementById(`count`).value-1;
//n=n+1;
//alert(n);
for(i=2;i<=n;i++)
{
if(document.getElementById(`reimb_date`+i).value =="" && document.getElementById(`reimb_billno`+i).value =="" && document.getElementById(`reimb_description`+i).value ==""){
//alert(i);
//alert(n);
document.getElementById(`reimb_bills`+i).disabled=true;
document.getElementById(`reimb_date`+i).disabled=true;
document.getElementById(`reimb_billno`+i).disabled=true;
document.getElementById(`reimb_description`+i).disabled=true;
}
}
}

function count(){
count=0;
for(j=1;j<=n;j++){
if(document.getElementById(`reimb_date`+j).value != "" && document.getElementById(`reimb_billno`+j).value != "" && document.getElementById(`reimb_description`+j).value !=""){
count=count+1;
}
}return count;
}

function reimb_val(){
n=document.getElementById(`count`).value-1;
//alert(n);
for(j=1;j<=n;j++){
if(document.getElementById(`reimb_date`+j).value == "" && j==1){
alert(`Bill Date in row `+j+` Should not be Empty`);
return false;
}
if(document.getElementById(`reimb_billno`+j).value == "" && j==1){
alert(`Bill No in row `+j+` Should not be Empty`);
return false;
}
if(document.getElementById(`reimb_description`+j).value == "" && j==1){
alert(`Bill Description in row `+j+` Should not be Empty`);
return false;
}
k=j-1;
if(document.getElementById(`reimb_date`+j).value == "" && document.getElementById(`reimb_billno`+j).value == "" && document.getElementById(`reimb_description`+j).value == "" && j>=2 &&
document.getElementById(`reimb_date`+k).value !="" && document.getElementById(`reimb_billno`+k).value !="" && document.getElementById(`reimb_description`+k).value !=""){
val_count=count();
alert(val_count);
window.location = `http://localhost/mafiree/admin/reimb_sub.php?ins=y&cnt`+val_count;
}
}
}

function reimb_active(n){
var r = n.match(/[d.]+/g);
i=r[0];
i=parseInt(i)+1;
document.getElementById(`reimb_bills`+i).disabled=false;
document.getElementById(`reimb_date`+i).disabled=false;
document.getElementById(`reimb_billno`+i).disabled=false;
document.getElementById(`reimb_description`+i).disabled=false;
}

Thanks in Advance,
Thiyaghu CK.

benaya
Posted on Apr 28, 2009
Join Date: June 2007
Location: India ( Chennai )
Posts: 90
 
RE : window.location not working  

Hi,
Try with this script for redirecting.

window.location.href ='http://www.codeasearch.com';


 Hot Discussion
Go Tech launches Android tablet for Rs 3,999...
Sony targets retailers with quick sales pitches and rew...
Share and discover new activities with Google Schemer...
Samsung gets 9 mn preorders for Galaxy S3: Report...
Google revamps search engine to think like a person...
 
 Discussion Topics
IT News
Php
Javascript
Technology Updates
Asp.Net
MySql
Ajax
Html
Fedora
Software Testing
Asp
Java
General
Flash
Ruby on Rails