jwigg5pt0
11-23-2009, 11:15 PM
i'm using a ajax request to be able to vote on a webpage without refresh. oh yea, i'm not really that great with javascript or ajax(noobie). i have the data posting and showing in an input as long as i am using the actual id name of the input field in the jfunction. i am passing a variable from the form on the asp page in the onclick call. there are going to be 10 items per page so each item is going to have a different "id" number for the input. the "id" is also for the id of the row in the db. here's the problem i'm having, i'm wanting to be able to pass the value into the javascript function and use that as the variable to update the field.
<script language="javascript" type="text/javascript">
<!--
function ajaxFunction(msgID, vote, inpID)
{
var ajaxRequest;
try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {try{ajaxRequest = new XMLHttpRequest();}
catch (e) {ajaxRequest = false}
}}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
document.myForm.VARIABLE.value=ajaxRequest.responseText;
}}
ajaxRequest.open("GET", "myURL", true);
ajaxRequest.send(null);
}
//-->
</script>
<form name='myForm'>
<%
do while intMsgCount < 6
inpID = "i"
inpID = inpID & rs1.fields("id").value
%>
<a href="javascript:void(0)" onclick="ajaxFunction('<%= rs1.fields("id").value%>', '', '<%= inpID%>')"><%=rs1.fields("id").value%></a>
<input id="<%= inpID%>" name="<%= inpID%>" value="<%=rs1.fields("vote_agree").value%>" />
<br />
<%
rs1.MoveNext
intMsgCount = intMsgCount + 1
loop
%>
</form>
the line that i'm having the problem with is ...
document.myForm.VARIABLE.value=ajaxRequest.responseText;
if i put what the variable should be, for example "i1" it works fine for that input, but i'm needing it for 10 different items. hence the reason for the variable.
this is just a test that i'm working on before completely implementing. just trying to see how this works before attempting to put it on the actual page.
on another side question... when the VARIABLE actually says "i1", internet explorer will only allow to update it 1 time. Mozilla and safari lets it do it unlimited, which i believe is coming from httprequest. any suggestions on that is apprciated.
<script language="javascript" type="text/javascript">
<!--
function ajaxFunction(msgID, vote, inpID)
{
var ajaxRequest;
try{ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");}
catch (e) {try{ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");}
catch (e) {try{ajaxRequest = new XMLHttpRequest();}
catch (e) {ajaxRequest = false}
}}
ajaxRequest.onreadystatechange = function()
{
if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200){
document.myForm.VARIABLE.value=ajaxRequest.responseText;
}}
ajaxRequest.open("GET", "myURL", true);
ajaxRequest.send(null);
}
//-->
</script>
<form name='myForm'>
<%
do while intMsgCount < 6
inpID = "i"
inpID = inpID & rs1.fields("id").value
%>
<a href="javascript:void(0)" onclick="ajaxFunction('<%= rs1.fields("id").value%>', '', '<%= inpID%>')"><%=rs1.fields("id").value%></a>
<input id="<%= inpID%>" name="<%= inpID%>" value="<%=rs1.fields("vote_agree").value%>" />
<br />
<%
rs1.MoveNext
intMsgCount = intMsgCount + 1
loop
%>
</form>
the line that i'm having the problem with is ...
document.myForm.VARIABLE.value=ajaxRequest.responseText;
if i put what the variable should be, for example "i1" it works fine for that input, but i'm needing it for 10 different items. hence the reason for the variable.
this is just a test that i'm working on before completely implementing. just trying to see how this works before attempting to put it on the actual page.
on another side question... when the VARIABLE actually says "i1", internet explorer will only allow to update it 1 time. Mozilla and safari lets it do it unlimited, which i believe is coming from httprequest. any suggestions on that is apprciated.