Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10

Thread: Form With Asp

  1. #1
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form With Asp

    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

    Code:
    <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

  • #2
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Quote Originally Posted by stevanicus View Post
    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 request and send your form value/s to the server-side ASP.

  • #5
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for all your help! i think i know what i should be looking at now.

  • #6
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    delete
    Last edited by stevanicus; 12-21-2007 at 01:36 PM. Reason: wrong post

  • #7
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Working but... :)

    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

    Code:
    <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>

  • #8
    Regular Coder
    Join Date
    Sep 2007
    Posts
    120
    Thanks
    0
    Thanked 3 Times in 3 Posts
    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

  • #9
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks. yea i wanted to do it all without leaving the page.. sorry maybe i didnt explain myself proper, and babbled on 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.

    Code:
    http://localhost/myasp/test.asp?txtArea=test123&Submit=Submit
    Code:
    <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
    Last edited by stevanicus; 12-21-2007 at 02:17 PM. Reason: typo

  • #10
    New Coder
    Join Date
    Dec 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    got it..

    i just added

    Code:
    <form method="post">
    thanks for eveyones help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •