Click to See Complete Forum and Search --> : Passing form value in Javascript


Squall Leonhart
11-19-2003, 12:44 PM
Hi, guys again:)
Please take a look at this code

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<script language="JavaScript" type="text/javascript">
function edit(){
if(document.frmEdit.selectEdit.options.selectedIndex<0){ alert("Items are not selected");
} else {
location.href='Request_edit.asp?state=update&ID=<%=Request.Form("selectEdit").value%>';
}
}
</script>

<title>IT Request Edit</title>
<link rel="stylesheet" href="http://myteam.multiactive.com/css/global.css" type="text/css">
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<form name="frmEdit" method="post" action="request_edit.asp?state=update&ID=<%=Request.Form("frmEdit")%>" onSubmit="return dateDiff(this);">
<table ALIGN=CENTER border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<th colspan="6" height="25"><b>Choose the item you want to edit</b></th>
</tr>
<tr>
<td width=1%>&nbsp</td>
<td align=center><span class="gen"><b>Description</b></span></td>
<td width=2%>&nbsp</td>

</tr>

<tr>
<td width=1%></td>
<td align=center><select name="selectEdit" style="width:300px;" size="6">
<% Do while not rsEdit.eof %>
<option value="<%=rsEdit.fields("ID")%>"><%=rsEdit.fields("description")%></option>
<% rsEdit.Movenext
Loop
%>
</select></td>
<td width=2%></td>
</tr>
<tr><td><br></td></tr>
</form>
<tr>
<th colspan="6" ><input type="submit" name="Edit" value="Edit" style="width:60px;" onclick="edit()">&nbsp&nbsp<button onClick="history.go(-1)" style="width:60px;">Go back</button></th>
</tr>
</table>
</BODY>
</HTML>


I just would like to send selected value of listbox to the other page.

It seems like something wrong on this part.

} else {
location.href='Request_edit.asp?state=update&ID=<%=Request.Form("selectEdit").value%>';
}
}
</script>

Not passing values as querystring.... Any solution guys?:(
Thanks

gil davis
11-19-2003, 04:20 PM
Are you and rjusa in the same class, or something? ;)

I believe that as soon as you provide a URL in location.href, the current page dies, and it doesn't get far enough to load the search part. Try loading the search part into location.search first and then load the URL into location.href.

Squall Leonhart
11-19-2003, 05:55 PM
Hi, gil
So I have written the code like this


function edit(){
if(document.frmEdit.selectEdit.options.selectedIndex<0){ alert("Items are not selected");
} else {
location.search='?state=update&ID=<%=Request.Form("selectEdit").value%>';
location.href='Request_edit.asp';
}
}

Still doesn't work.....:(
What should I do?

gil davis
11-19-2003, 07:25 PM
Here is a novel idea:

<script ...>
function edit(){
if(document.frmEdit.selectEdit.options.selectedIndex<0){ alert("Items are not selected");
} else {
document.hid.submit();
}
}
</script>
...
<div id="trick" style="visibility: hidden; position: absolute; top:0 left:0">
<form name="hid" action="Request_edit.asp" method="get">
<input type="text" name="state" value="update">
<input type="text" name="ID" value="<%=Request.Form("selectEdit").value%>">
</form>
</div>

This probably won't work in NS 4.