943,880 Members | Top Members by Rank

Ad:
Jul 10th, 2008
0

Onchange

Expand Post »
Hi
I am new to javascript.
I have two drop downs used to reload the page displaying selected information.

How do I get the OnChange function to pass year and user form the drop down.
I also need to pass data in the array $month.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <body>
  4. <script language="JavaScript" type="text/JavaScript">
  5. <!--
  6.  
  7. function OnChange(dropdown)
  8. {
  9. //reload page after drop down selection
  10. window.location.href="http://localhost/month_view.php?u_user_id=" +
  11. dropdown.options[dropdown.selectedIndex].value "&year="+ "&month="+ ;
  12. }
  13. --->
  14.  
  15.  
  16. <table>
  17. <tr><td>
  18. <!--year drop down-->
  19. <select name ="year" onChange ="javascript:OnChange(this)"
  20. <option value="">Select</option>
  21. <option value="2007">2007</option>
  22. <option value="2008">2008</option>
  23. </select>
  24.  
  25.  
  26.  
  27. <select name = "user_id" onChange ="javascript:OnChange(this)"
  28. <option value="">Select</option>
  29. <option value="1">Frank</option>
  30. <option value="2">Mark</option>
  31. </select>
  32.  
  33. </td>
  34. </tr>
  35. <tr>
  36. <td>
  37. <?php
  38. //display information based on selected year, month and user
  39. display_info($year, $month, $user);
  40. ?>
  41.  
  42. </td>
  43. </tr>
  44. </table>
  45. </body>
  46. </head>
  47. </html>
Similar Threads
Reputation Points: 24
Solved Threads: 0
Junior Poster in Training
assgar is offline Offline
89 posts
since Oct 2006
Jul 10th, 2008
0

Re: Onchange

First - it looks like you are trying to re-load the page to early. It is the first line in your function - so you will lose whatever was selected in the drop down.

Clean way is just make a var:

var year;

and assign it to the value of the dropdown at the **beginning** of your function

year = options[dropdown.selectedIndex].value;

if you need to use both year AND user when you refresh the page - then instead of passing (this) from the onchange hander - just give an id to each SELECT element and then look up each one with document.getElementById() in your function.

Then you can get the year and the user before you refresh the page again.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kceleb9 is offline Offline
17 posts
since Jul 2008
Jul 13th, 2008
0

Re: Onchange

Hi

Thanks for the response and suggestion.
I could not a single function to work.
I could get 2 seperate functions working and it does the job.

I am curious why your suggestion won;t work as one function but will wor as two?

solution

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html>
  2. <head>
  3. <script language="javascript" type="text/javascript">
  4.  
  5. function YearChange()
  6. {
  7. var year = document.getElementById('year').value;
  8. window.location.href="http://localhost/month_view.php?year=" + year;
  9. }
  10.  
  11. function ProChange()
  12. {
  13. var providerId = document.getElementById('provider_id').value;
  14. window.location.href="http://localhost/month_view.php?u_org_pro_id=" + providerId;
  15. }
  16.  
  17. </script>
  18. </head>
  19. <body>
  20. <table>
  21. <tr><td>
  22.  
  23. <select name= "year" onchange="javascript:YearChange();">
  24. <?
  25. //dynamic year dropdown 14 years (4 back, current and 9 forward)
  26. year_only($year);
  27. ?>
  28. </select>
  29.  
  30.  
  31. <select name= "user_id" onchange="javascript:ProChange();">
  32. <?
  33. //display information based on selected year, month and user
  34. display_info($year, $month, $user);
  35. ?>
  36. </select>
  37.  
  38. </td>
  39. </tr>
  40. </table>
  41. </body>
  42. </html>
Last edited by assgar; Jul 13th, 2008 at 10:10 pm.
Reputation Points: 24
Solved Threads: 0
Junior Poster in Training
assgar is offline Offline
89 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Acrobat 5.0 and JavaScript
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: simple javascript syntax errors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC