473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

JavaScript form within ASP.NET webpage

I am converting a site from classic ASP to ASP.NET (2.0).

One page has the following JS form:
Expand|Select|Wrap|Line Numbers
  1. <body>
  2.  
  3. <script language="JavaScript">
  4.  var Makes0Array = new Array(new Array('0','Select model   '));
  5.  var Makes1Array = new Array(new Array('3','145'),new Array('11','Spider'));
  6.  var Makes2Array = new Array(new Array('12','A2'),new Array('311','A3'));
  7.  
  8.  function SwitchMakes() {
  9.     var Makes = document.searchCriteria.CarMakes.options[document.searchCriteria.CarMakes.selectedIndex].value;
  10.     var modelindex = document.searchCriteria.CarModels.selectedIndex;
  11.     var length = eval('Makes'+Makes+'Array.length');
  12.  
  13.     for (i = document.searchCriteria.CarModels.length-1; i >= 0; i--)
  14.         {document.searchCriteria.CarModels.options[i] = null;}
  15.  
  16.     var numberOfElements = 0;
  17.  
  18.     for (var x = 0; x < length; x++)
  19.         {var newoption = new Option(eval('Makes'+Makes+'Array[x][1]'), eval('Makes'+Makes+'Array[x][0]'), true, true);
  20.         document.searchCriteria.CarModels.options[document.searchCriteria.CarModels.length] = newoption;
  21.         numberOfElements++;}
  22.  
  23.     if ((modelindex >= 0) && (modelindex < numberOfElements))
  24.         {document.searchCriteria.CarModels.selectedIndex = modelindex;}
  25. }
  26.  
  27. function submitForm()
  28.   {document.searchCriteria.submit();}
  29. </script>
  30.  
  31. <form method="get" action="show_model.asp" name="searchCriteria">
  32.     <p>Make</p>
  33.     <select name="CarMakes" onchange="SwitchMakes()">
  34.     <option value="0">Select make</option>
  35.     <option value="1">Alfa Romeo</option>
  36.     <option value="2">Audi</option>
  37.     </select>
  38.  
  39.     <p>Model</p>
  40.     <select name="CarModels"></select>
  41.  
  42.     <a href="javascript:submitForm()"><input type="submit" value="go" /></a>
  43. </form>
  44.  
  45. </body>
Of course, as soon as this code is placed within the ASP.NET <FORM> tags the code will no longer work. As a beginner I am a loss as to how to get it to work again.

Please help!
Sep 25 '08 #1
3 1607
DrBunchman
979 Expert 512MB
Hi misterdavid,

Welcome to Bytes.com! I hope you find the site useful. Please don't forget to wrap your code in CODE tags - it makes your posts much easier to read - and please read the Posting Guidelines if you have not done so already. Thanks.

What is it that this javascript is trying to achieve?

Dr B
Sep 26 '08 #2
Hi DrB, thanks for responding to my question.

The javascript is tried and tested (it produces two drop down lists, the contents of the second depending on the selection made from the first) when incorporated in a classic ASP page.

The only problem I am having is getting the script to work within an ASP.NET type page.

As soon as the javascript form is inseted between the ASP.NET form tags, it fails.
Sep 26 '08 #3
Frinavale
9,735 Expert Mod 8TB
Hi DrB, thanks for responding to my question.

The javascript is tried and tested (it produces two drop down lists, the contents of the second depending on the selection made from the first) when incorporated in a classic ASP page.

The only problem I am having is getting the script to work within an ASP.NET type page.

As soon as the javascript form is inseted between the ASP.NET form tags, it fails.
You cannot use JavaScript to populate ASP.NET DropDownList controls.
This is because the server checks to make sure that the controls have not been modified...since the JavaScript modifies what is listed in the it will fail validation.

You should create and populate your DropDownList in your sever side code instead of using JavaScript.

-Frinny
Sep 26 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.