aspquestions Posted October 16, 2009 Share Posted October 16, 2009 Hello,I have a snippet of code<% VARIABLE = document.getElementByID("controlname).text %> How do I do this so it works across all browsers? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 16, 2009 Share Posted October 16, 2009 document.getElementByID does work across all browsers, but that's Javascript code, not ASP code. document.getElementByID doesn't have any meaning in server-side code, only client-side Javascript. Link to comment Share on other sites More sharing options...
aspquestions Posted October 16, 2009 Author Share Posted October 16, 2009 document.getElementByID does work across all browsers, but that's Javascript code, not ASP code. document.getElementByID doesn't have any meaning in server-side code, only client-side Javascript.I need to pass in the value of a textbox as a parameter to one of my functions which is in server side code. How do I do that? Link to comment Share on other sites More sharing options...
aspquestions Posted October 16, 2009 Author Share Posted October 16, 2009 I guess a better way to ask my question is ... is there a function similar to Request.Form but instead doesn't need to have a postback? Link to comment Share on other sites More sharing options...
justsomeguy Posted October 17, 2009 Share Posted October 17, 2009 If you want to send any data to a server-side script without refreshing the page, you can use ajax for that. So that will use Javascript to get the form values, add them to your own post request, and send the post request to whatever ASP page you want. The ASP page will be able to find that data in Request.Form, but since you used Javascript to send the data it won't cause the page to refresh. The ASP can process the data and output a response, and Javascript can get the response from the server and use it to update the page, all without refreshing anything.There's some ajax Javascript code here:http://w3schools.invisionzone.com/index.ph...st&p=116840In order to use that to send your request, you can gather up all of the data and then use the sendRequest function to send it, and then you also need another function to handle the response. e.g.: var postData = { var1: document.getElementById('field1').value, var2: document.getElementById('field2').value, var3: document.getElementById('field3').value};function handleResponse(resp){ alert('server resopnse: ' + resp.responseText); // update the page with the response}sendRequest('post.asp', handleResponse, postData); Note that all of that is Javascript that goes inside the HTML portion, that's not ASP code. The ASP code would be the same as any other form processing, you would read e.g. Request.Form("val1") to get the values. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.