Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 16th, 2006, 02:57 PM
Authorized User
 
Join Date: Mar 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Is this even possible?

(NOTE: I am posting this here because it deals more with Javascript than with ASP. Please move it if it's still unappropriate).

I'm developing a form in Classic ASP and want to do some validation; pretty much I need to make sure that a username entered doesn't already exist in the database. However, I need to do this validation before the page is submitted (otherwise, it erases all the data the user already entered). I have a javascript function called checkName which I call from the onBlur event of a text field (called "userName"). checkName takes a single parameter: name; the value of the textbox.. now here's the problem:

Is there any way to pass the value of name to my ASP function, UserExists(userName), from javascript?

e.g.

function checkName(name)
{
    var userExists = '<%=UserExists(' + name + ')%>';

    if (userExists == true)
    {
        alert("That username is already registered.");
        addAdmin.userName.value = "";
        addAdmin.userName.focus();
    }
}

I know it's possible to write variables from ASP to Javascript, but when I attempt the code above it prints out the literal value of name (i.e. "+ name +") and not the value contained in it.

Is there any way to do this, or failing that some suggestion to avoid having the user lose all the data they submit if I'm forced to call the script after they submit?

 
Old May 26th, 2006, 08:41 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think your trying to send a variable from javascript to asp variable.
This is not posible because the javascript is client side and asp is server side.
In other words javascript is only executed on the browser and the asp on the web server.

How ever there are ways to work around it. You can use the post method to post these variables to a other asp page and read this serverside.

Or you can use AJAX (execute a asp page via javascript while your active asp on the browser will still be the same and the javascript can refresh a part of the webpage.

hope this awsers your question.


__________________________________________________ ________
This is my junk I'm gona eat it
 
Old May 26th, 2006, 09:11 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii wayne62682!!
There are two ways.
1>Use iframe to post your data of one frame to another frame
  and if get success ,jump to loginsuccess/whtever page as per ur requirement

2>Use ajax/xmlhttp request that will first check the username on ur database whether it exists or not ,then depending on yes/no or 1/0 flag you can allow the actual submisson of the form for entered userid.
Note-more than one user can enter the same userid for registration,so to whom you give the requested userID ;P ;)
  You can use temporary table ,that will store currently requested userId and allow to only one user (yes/no) flag.
so if Person A is requsting for userId "abcd1919" and
Person B is requsting for the same userId "abcd1919"

whoever either A or B ,first request to the server ,will save the "abcd1919" as userid in temp table ,and not allowed to another reqeust for same userID.

  periodically you can delete unused UserID from temptable

Hope this will help you



Cheers :)

vinod









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.