...

View Full Version : Form With Asp



stevanicus
12-20-2007, 06:35 PM
hi at the moment im using javascript to catpure the value from a text area. however I would like to catpure it using asp.

this is the code i have at the mo


<html>
<script type="text/javascript">
function validate_email(field)
{
with (field)
{
alert(value);
}
}

function validate_form(thisform)
{
with (thisform)
{
validate_email(txtArea);
}
}
</script>
<body>
<table>
<tr><td><form onsubmit="validate_form(this);">
<tr><td><textarea rows="10" cols="50" name="txtArea"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</tr></td>
</table>
</body>
</html>

how can i get alert(value) - value and do something with it in asp? without leaving the page.

thanks

stevanicus

Whatever Jr.
12-21-2007, 06:54 AM
Hi,
How does this sound:

- Post the form
- Use request.form to capture form value
- Do something with value
- Redirect to same page

HTH, Tom

provo
12-21-2007, 10:53 AM
The problem is, that java is run on the client side and ASP is run on the server side, so ASP code is not there on the client side. Whatever Jr is right, or you may try use a control <input OnChange=Alert(SomeValue) >

Provo

Spudhead
12-21-2007, 11:39 AM
how can i get alert(value) - value and do something with it in asp? without leaving the page.

Use AJAX. In the JavaScript, create a XMLHTTP (http://en.wikipedia.org/wiki/XMLHttpRequest)request and send your form value/s to the server-side ASP.

stevanicus
12-21-2007, 01:06 PM
thanks for all your help! i think i know what i should be looking at now.

stevanicus
12-21-2007, 01:20 PM
delete

stevanicus
12-21-2007, 01:35 PM
hi again,

i got it working... however, how can i sent the data without it appearing in the address bar?

thanks for all your help again


<html>
<script type="text/javascript">

function ajaxFunction(str)
{
var xmlHttp;
var url="loadData.asp";
url=url+"?q="+str;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function submit_data(field)
{
with (field)
{
ajaxFunction(value);
}
}

function load_form(thisform)
{
with (thisform)
{
submit_data(txtArea);
}
}
</script>
<body>
<table>
<tr><td><form onsubmit="load_form(this);">
<tr><td><textarea rows="10" cols="50" name="txtArea"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit"></td></tr>
</form>
</tr></td>
</table>
</body>
</html>

Whatever Jr.
12-21-2007, 01:49 PM
Hi,

Why are you using AJAX? Did I misunderstand the question?

I thought you wanted to submit a form and do 'something' to a value within that form in ASP. If you're going the AJAX route, I'd suggest:

- create function to create XMLHTTP object
- create function to POST/GET to ASP page
- create function to handle XMLHTTP response

That way data won't appear in the address bar.

HTH, Tom

stevanicus
12-21-2007, 02:04 PM
thanks. yea i wanted to do it all without leaving the page.. sorry maybe i didnt explain myself proper, and babbled on :D hehe.

im new to ajax - not really sure how to do what you said - so i w3schooled it, and did the tutorial on ajax. i got the following code. and it works. but it still displays it in the address bar.


http://localhost/myasp/test.asp?txtArea=test123&Submit=Submit


<script type="text/javascript">
function ajaxFunction(str)
{
var xmlHttp;
var url="loadData.asp";
url=url+"?q="+str;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
</script>
<body>
<table>
<tr><td><form>
<tr><td><textarea rows="10" cols="50" name="txtArea"></textarea></td></tr>
<tr><td><input type="submit" name="Submit" value="Submit" onmousedown="ajaxFunction(txtArea.value);"></td></tr>
</form>
</tr></td>
</table>
</body>
</html>

thanks again

stevanicus
12-21-2007, 02:18 PM
got it..

i just added


<form method="post">

thanks for eveyones help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum