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 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    code for passing vars to a pop up

    Hi,

    it's a long story, but i'll try to make it brief...

    i have a friend who has a html only site and i have helped him out with some cold fusion functions to make it a bit more effective. prob for me is my js is terrible. this is what i need to be able to do...

    user on his site enters name and email address in newsletter sign up box (in the template and so is on every page). the action for this form is a page on my server which inserts the data into a database. i want to use cgi.http_referer to return the user to the same page they were on... so far so good.

    if the user has not entered both fields, i want to pass a var back to the referering page that spawns a pop up and says 'error. blah blah'. if the entry is correct, i want to pass a var back that says 'you have been added....etc'.

    soooooo - seems like what i need is:

    1. what does the returning link look like, ie. "cgi.http_referer?var=Error. Both fields are required."

    2. then an if statement wrapped around the pop up code that asks if the var exists to spawn the pop up, otherwise don't.

    3. then, how do i output the var in the pop up.

    seems like 1 and 3 are more of a syntax issue and 2 - i have this basic pop up code which seems to work fine...

    <script>

    function openpopup(){
    var popurl="result.htm"
    winpops=window.open(popurl,"","width=330,height=80,")
    }

    openpopup()

    </script>

    any help would be greatly appreciated.

  • #2
    New Coder
    Join Date
    Sep 2002
    Location
    Moncton, N.B., Canada
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The onsubmit can be used to call a function and check for empty variables etc. You can then write a custom message in a popup or alert based on form field tests. Try something like this:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function formValidate()
    {
    	var validated = true;
    	if(!validate(document.forms.user.n, document.forms.user.e) )
    	validated = false;
    
    	return validated;
    }
    
    
    function validate(obj, obj2)
    {
    	if( (obj.value.length > 0) && (obj2.value.length > 0) )
    	{
    		msg = "you have been added....etc";
    		alert(msg);
    		return true;
    	}
    	else
    	{
    		msg = "error. Empty Fields(s)";
    		alert(msg);
    	}
    	return false;
    }
    </script>
    </head>
    
    <body>
    
    <form name="user" action="p.htm" method="get" onsubmit="return formValidate()">
    Name: <input type="text" name="n" /><br />
    Email: <input type="text" name="e" /><br />
    <input type="submit" />
    </form>
    
    </body>
    </html>
    - Terry

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi Terry,

    now that's lateral thinking! took me a while to work out how this would solve ALL my problems... but i got it!

    thanks for your thinking... i really appreciate it!

    jo


  •  

    Posting Permissions

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