SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript and CGI

    Ok, I have a form created in HTML and I am sending it via email to whomever needs it. But the email is the raw code with variable names and values. Is there a way to write a Javascript to parse the form before sending it? I know that a solution lies in php, but the server that hosts the site doesn't support php (Not my choice). I have been told that CGI is used for this as well, but I thought CGI was only used with server-side languages? Is there a way to use CGI with Javascript? Help on any of this?

    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.

  2. #2
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use JavaScript inconjunction with a CGI to do some validation and other things, but CGI is used on the server side so if you don't have access to CGI then that won't work. You can use JavaScript to build the contents of the body of the email, but it will only cut down on the variable names that you would see. What you could do is create two forms, one to collect the information and then the second one to send it out. Here is an example:
    <html>
    <head>
    <title>Tell A Friend</title>
    <SCRIPT LANGUAGE="JavaScript">
    function buildmsg()
    {
    df=document.bldlink
    if(df.fname.value.length<1)
    {
    alert("Please enter your friends name.")
    df.fname.focus()
    return false
    }
    else
    {
    if(df.femail.value.indexOf("@")==-1 ||
    df.femail.value.indexOf(".")==-1 ||
    df.femail.value.indexOf(" ")!=-1 ||
    df.femail.value.length<6)
    {
    alert("The Email address for your friend must have a @ sign,\r a period and be at least 6 characters long.")
    df.femail.focus()
    return false
    }
    else
    {
    if(df.yname.value.length<1)
    {
    alert("Please enter your name.")
    df.yname.focus()
    return false
    }
    else
    {
    document.sndlink.action="mailto:"+df.femail.value+"?subject= link from "+df.yname.value
    document.sndlink.message.value="\rHello "+df.fname.value+" your friend "+df.yname.value+" thought you might\r want to check out this site, a greate site for what ever you need.\rCheck out the link below and find out what it\'s all about!\r http://www.yoursite.com"+" \r"+df.pmsg.value
    }
    }
    }
    }
    </SCRIPT>
    </head>
    <body onLoad="document.bldlink.reset();document.sndlink.reset();document.bldlink.fname.focus()" BGCOLOR="lightyellow">
    <BR>
    <CENTER>
    <H2>Send the Your Site link to a friend</H2>
    <FORM name="bldlink">
    Please enter your friends name &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp Please enter their email address
    <BR>
    <INPUT TYPE="text" SIZE="30" NAME="fname" MAXLENGTH="30">
    <INPUT TYPE="text" SIZE="30" NAME="femail" MAXLENGTH="30">
    <BR><BR>
    Please enter your name
    <BR>
    <INPUT TYPE="text" SIZE="30" NAME="yname" MAXLENGTH="30">
    <BR><BR>
    Enter your personal message below
    <BR>
    <TEXTAREA NAME="pmsg" ROWS="6" COLS="60" WRAP="hard" onFocus="document.bldlink.pmsg.select()">Enter a personal message to your friend.</TEXTAREA>
    </FORM>
    <FORM name="sndlink" method="post" action="" enctype="text/plain" onSubmit="return buildmsg()">
    <INPUT TYPE="hidden" NAME="message">
    <INPUT TYPE="submit" VALUE="Send It"> &nbsp &nbsp <INPUT TYPE="reset" VALUE="Clear the form" onClick="document.bldlink.reset();document.bldlink.fname.focus()">
    </FORM>
    </CENTER>
    </body>
    </html>

  3. #3
    SitePoint Zealot Drew630's Avatar
    Join Date
    Nov 2001
    Location
    Maryland
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you so much requestcode! That example not only helped me to undertand what I am trying to do, but it worked in giving me exactly what I am looking for. Thanks again.

    Drew
    ~Drew

    There Is No Greater Joy Than Soaring High On The Wings Of Your Dreams, Except Maybe The Joy Of Watching A Dreamer Who Has Nowhere To Land But In The Ocean Of Reality.


Bookmarks

Posting Permissions

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