Link to home
Start Free TrialLog in
Avatar of denam
denam

asked on

vbscript, forms, action

I'm trying to set the action in a form using a select.
I've stolen an example right out of the book, but my
script fails.  What am I doing wrong?
Avatar of denam
denam

ASKER

Here's my form.  When someone selects a country, I want to go to a file
under a directory for that country.
===============================================================
<html>
<head>
<title></title>
<SCRIPT Language = "VBScript">
<! --
Sub submitform()
  Dim f
  Dim sUrl
  set f = Document.frmMain
  sUrl = "&#34/private/membership/" & sWhereToGo.Value & "/default.asp&#34"
  f.Method = "Post"
  f.Action = sUrl
  f.submit
end sub
-->
</script>

<!--#include file="/private/includes/header1.txt"-->
<blockquote>
<p><font color="#408080"><strong><big>Member's Area</big></strong></font></p>

<form name="frmMain">
    <select>
      <option value="membersarea/default.htm">Argentina</option>
      <option value="Austrailia">Australia</option>
      <option value="Austria">Austria</option>
      <option value="Barbados">Barbados</option>
      <option value="Belgium">Belgium</option>
      <option value="Bermuda">Bermuda</option>
      <option value="Canada">Canada</option>
      <option value="Cayman Islands">Cayman Islands</option>
      <option value="Channel Islands">Channel Islands</option>
      <option value="Chile">Chile</option>
      <option value="Denmark">Denmark</option>
      <option value="England">England</option>
      <option value="Hong Kong">Hong Kong</option>
      <option value="Italy">Italy</option>
      <option value="Japan">Japan</option>
      <option value="Liechtenstein">Liechtenstein</option>
      <option value="Mexico">Mexico</option>
      <option value="Monaco">Monaco</option>
      <option value="Scotland">Scotland</option>
      <option value="South Africa">South Africa</option>
      <option value="Sweden">Sweden</option>
      <option value="Switzerland">Switzerland</option>
      <option value="The Netherlands">The Netherlands</option>
      <option value="U.S.A.">U.S.A.</option>
    </select><input type=Button OnClick=submitform value="Go"></p>
  </form>
</blockquote>
<!--#include file="/private/includes/footer1.txt"-->
</body>
</html>

Avatar of denam

ASKER

the option value for the first selection (Argentina) is wrong in the previous comment.
it should just be "Argentina"
I don't see any form element named 'sWhereToGo' in the code you posted, which was used in setting the Action in VBScript. This might be the reason for the failure. It might be the name of the SELECT you're using. So, give that name to the SELECT and see.
Avatar of denam

ASKER

the error i get is:

JavaScript Error: line 68:
submitform is not defined.

and, my apologies, i copied the wrong example into the comment box.  It should have
been:

<html>
<head>
<title>TIAETL Membership</title>
<SCRIPT Language = "VBScript">
<! --
Sub submitform()
  Dim f
  Dim sUrl
  set f = Document.frmMain
  sUrl = "&#34/private/membership/" & f.WhereToGo.Value & "/default.asp&#34"
  f.Method = "Post"
  f.Action = sUrl
  f.submit
end sub
-->
</script>

<!--#include file="/private/includes/header1.txt"-->
<blockquote>
<p><font color="#408080"><strong><big>Member's Area</big></strong></font></p>

<form name="frmMain">
    <select name="WhereToGo">
      <option value="Argentina">Argentina</option>
      <option value="Austrailia">Australia</option>
      <option value="Austria">Austria</option>
      <option value="Barbados">Barbados</option>
      <option value="Belgium">Belgium</option>
      <option value="Bermuda">Bermuda</option>
      <option value="Canada">Canada</option>
      <option value="Cayman Islands">Cayman Islands</option>
      <option value="Channel Islands">Channel Islands</option>
      <option value="Chile">Chile</option>
      <option value="Denmark">Denmark</option>
      <option value="England">England</option>
      <option value="Hong Kong">Hong Kong</option>
      <option value="Italy">Italy</option>
      <option value="Japan">Japan</option>
      <option value="Liechtenstein">Liechtenstein</option>
      <option value="Mexico">Mexico</option>
      <option value="Monaco">Monaco</option>
      <option value="Scotland">Scotland</option>
      <option value="South Africa">South Africa</option>
      <option value="Sweden">Sweden</option>
      <option value="Switzerland">Switzerland</option>
      <option value="The Netherlands">The Netherlands</option>
      <option value="U.S.A.">U.S.A.</option>
    </select><input type=Button OnClick=submitform value="Go"></p>
  </form>
</blockquote>
<!--#include file="/private/includes/footer1.txt"-->
</body>
</html>

Avatar of denam

ASKER

btw, the form is saved with a .htm extension.
Which browser you're using to test this page?
Which browser you're using to test this page?
Avatar of denam

ASKER

btw, the form is saved with a .htm extension.
Avatar of denam

ASKER

i'm Netscape navigator 4.05
No problem, .htm extension is not the reson for your problem
Avatar of denam

ASKER

i'm Netscape navigator 4.05
ASKER CERTIFIED SOLUTION
Avatar of rajgn
rajgn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of denam

ASKER

Thanks rajgn.
Avatar of denam

ASKER

is there any good online reference that can show me how to do this in javascript?
thx.
Just hold on for a sec. I'll be back to you...
Avatar of denam

ASKER

is there any good online reference that can show me how to do this in javascript?
thx.
Have a look at:
http://developer.netscape.com/tech/javascript/resources.html 
for various JavaScript resources. Hope you like it. Here I'm writing the same function in JavaScript, for you. Try it out. If you've any probs. can get back to me.

<SCRIPT Language = "JavaScript">
       function submitform() {
         var sUrl
         sUrl = "&#34/private/membership/" + sWhereToGo.Value + "/default.asp&#34"
         Document.frmMain.Method = "Post"
         Document.frmMain.Action = sUrl
         Document.frmMain.submit()
 }
       </script>

make a change in button's code as follows:

onClick="submitform()"
Avatar of denam

ASKER

is there any good online reference that can show me how to do this in javascript?
thx.
Avatar of denam

ASKER

wow, thanks.  that's really above and beyond!
You're welcome...