SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: ASP / Functions

  1. #1
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Wilmington, NC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP / Functions

    I created an asp search page which allows the user to choose the range of matching records. The database records are houses, and one of the fields is Price. The search page allows the user to select the price range of houses s/he wants to view. I also included a javascript function to make sure that the user selects a valid range where the minimum price is less than the maximum price. (For example, so that the user cannot submit a request to view houses ranging from $500,000 to $200,000!)

    However, the function is not working. It only works if the user has chosen $0 for the minimum OR No Limit for the maximum.

    Here is the live page if you would like to try it out www.brettknowles.com/search.asp

    And here is the relevant code:
    function verify() {
    if ((document.frmSearch.mnuMinPrice.value > document.frmSearch.mnuMaxPrice.value) == true) {
    alert (' The Price range is incorrect. The from price must be less than the to price.');
    return false;
    }

    <select name="mnuMinPrice" class="form">
    <option value="0">$0</option>
    <option value="50000">$50,000</option>
    <option value="60000">$60,000</option>
    <option value="70000">$70,000</option>
    and so on for the remaining values 'til the end....
    <option value="490000">$490,000</option>
    <option value="500000">$500,000+</option>
    </select>

    <select name="mnuMaxPrice" class="form">
    <option value="59999">$59,999</option>
    <option value="69999">$69,999</option>
    <option value="79999">$79,999</option>
    and so on for the remaining values 'til the end ...
    <option value="499999">$499,999</option>
    <option value="9999999" selected>No limit</option>
    </select>

    Help!

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following Seabelle.

    I'm no JS expert so this may not be the correct way.

    Code:
    <script type="text/javascript">
    	
    function verify() { 
    	
    	var minPrice = eval(document.frmSearch.mnuMinPrice.value);
    	var maxPrice = eval(document.frmSearch.mnuMaxPrice.value);
    
    	if ((minPrice > maxPrice)) { 
    		alert (' The Price range is incorrect. The from price must be less than the to price.'); 
    		return false; 
    	}
    } 	
    
    </script>

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Wilmington, NC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Shane, unfortunately this did not work. I understand the logic of both our functions and cannot for the life of me figure out why they are producing incorrect error messages!

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE 6, NT 4...it works for me. I chose Min 60,000 and max 59,999 and got the error message.

    sketch
    Aaron Brazell
    Technosailor



  5. #5
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Wilmington, NC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sketch,
    Would you mind trying a range that should work (i.e. no error message should display), such as $50,000 to $229,999? These are the instances where I'm getting the error message ... even though the range is valid.
    Thanks!

  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're right, there is an error then. try this.
    Code:
    function verify() {
      var mnuMinPrice = eval(document.frmSearch.mnuMinPrice.value);
      var mnuMaxPrice = eval(document.frmSearch.mnuMaxPrice.value);
       
      if (!mnuMinPrice) {
        alert("Please select a minimum price.");
        return false;
      } else if (mnuMinPrice.value >= mnuMaxPrice.value) {  
          return true;
        } 
    }
    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think Sketch may have got but if not try this.

    Code:
    <script type="text/javascript">
    
    function verify() { 
    	
    	var minPrice = -1;
    	var maxprice = -1;
    	
    	//Get the select objects
    	objMinPrice = eval(document.frmSearch.mnuMinPrice);
    	objMaxPrice = eval(document.frmSearch.mnuMaxPrice);
    	
    	//Get the selected indexes of the select objects
    	minPriceIdx = objMinPrice.selectedIndex;
    	maxPriceIdx = objMaxPrice.selectedIndex;
    	
    	//Get the selected min and max prices
    	if ((minPriceIdx != -1) && (maxPriceIdx != -1)) {
    		minPrice = objMinPrice.options[minPriceIdx].value;
    		maxPrice = objMaxPrice.options[maxPriceIdx].value;
    	}
    	
    	//Check the min and max prices
    	if ((minPrice == -1) || (maxPrice == -1) || (minPrice > maxPrice)) {
    		alert (' The Price range is incorrect. The from price must be less than the to price.'); 
    		return false; 
    	}
    	else
    		alert('Valid price range: ' + minPrice + ' - ' + maxPrice);	
    
    } 	
    
    </script>

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Wilmington, NC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sketch, this change you provided the fix! Thanks!

    Can you tell me what is the difference that corrected the problem? I see it working, but don't follow why!

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2001
    Location
    Wilmington, NC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoop! Shane, I think we posted at the same time. I did not see your note until after I sent mine. Thanks for sharing your suggestion as well. Site Point is The Best!

    Now if I can understand why my function did not work, I'll be feeling a little like a pro!

  10. #10
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I first started rewriting the code to make it flow better. Then I realized that you were just using mnuMinPrice and mnuMaxPrice when you should have been comparing mnuMinPrice.value and mnuMaxPrice.value. That's the problem. Glad I could help.

    Sketch
    Aaron Brazell
    Technosailor




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
  •