473,394 Members | 1,852 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,394 software developers and data experts.

ListItems added using Js gets cleared on Page load?

Hi ALL,
I am binding ListItems to dropdownlist using js.But the selected value is not retained while save operation. Do I need to capture the selected Item in any hiddenfields ?
plz tell me

Sudha
Oct 10 '07 #1
25 2089
dmjpro
2,476 2GB
Hi ALL,
I am binding ListItems to dropdownlist using js.But the selected value is not retained while save operation. Do I need to capture the selected Item in any hiddenfields ?
plz tell me

Sudha
Your save operation gets processed properly or it stops to do that?
Let me know.
I think when you submit the page then according to browser settings this happnes.
I think it should not harm your page submitting.

Debasis Jana
Oct 10 '07 #2
Your save operation gets processed properly or it stops to do that?
Let me know.
I think when you submit the page then according to browser settings this happnes.
I think it should not harm your page submitting.

Debasis Jana
This is my Code. I dont know why this is happening its due to Ajax or due to any wrong with my code
Expand|Select|Wrap|Line Numbers
  1. function Major()
  2. {
  3. var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  4.  
  5.  if(deg.selectedIndex != 0)
  6.     {
  7.     AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
  8.     }
  9.  
  10. }
  11. function OnGetMajor(Items)
  12. {
  13.  
  14. var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
  15. if(major.options.length > 0)
  16. {
  17. major.options.length = 0;// to remove previously binded items
  18. }
  19. var o = document.createElement("option");
  20. o.text = "----Select----";
  21. o.value = 0;
  22. major.add(o);
  23. for(i=0;i<Items.length;i++)
  24. {
  25. var options = Items[i].split(",");
  26. var o = document.createElement("option");
  27. o.text = options[1];
  28. o.value = options[0];
  29. major.add(o);
  30. }
  31. }
Can you find out?
Oct 10 '07 #3
Your save operation gets processed properly or it stops to do that?
Let me know.
I think when you submit the page then according to browser settings this happnes.
I think it should not harm your page submitting.

Debasis Jana
I have kept these fields mandatory and only if these listitems are not null it will get saved. But the listitems are getting cleared during page load.
Oct 10 '07 #4
dmjpro
2,476 2GB
This is my Code. I dont know why this is happening its due to Ajax or due to any wrong with my code
Expand|Select|Wrap|Line Numbers
  1. function Major()
  2. {
  3. var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  4.  
  5.  if(deg.selectedIndex != 0)
  6.     {
  7.     AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
  8.     }
  9.  
  10. }
  11. function OnGetMajor(Items)
  12. {
  13.  
  14. var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
  15. if(major.options.length > 0)
  16. {
  17. major.options.length = 0;// to remove previously binded items
  18. }
  19. var o = document.createElement("option");
  20. o.text = "----Select----";
  21. o.value = 0;
  22. major.add(o);
  23. for(i=0;i<Items.length;i++)
  24. {
  25. var options = Items[i].split(",");
  26. var o = document.createElement("option");
  27. o.text = options[1];
  28. o.value = options[0];
  29. major.add(o);
  30. }
  31. }
Can you find out?
At which point your Ajax Call made and where your "Select Box" gets cleared?
Let me know ... Quick!

Debasis Jana
Oct 10 '07 #5
dmjpro
2,476 2GB
I have kept these fields mandatory and only if these listitems are not null it will get saved. But the listitems are getting cleared during page load.
What do you mean by "Page Load"?
What is your sever side Script?

Debasis Jana
Oct 10 '07 #6
At which point your Ajax Call made and where your "Select Box" gets cleared?
Let me know ... Quick!

Debasis Jana
onchange event of degree, i have called the js.In that code only i'm calling ajax;
But i trying to find where actually listitems is getting cleared
Oct 10 '07 #7
dmjpro
2,476 2GB
onchange event of degree, i have called the js.In that code only i'm calling ajax;
But i trying to find where actually listitems is getting cleared
If you are using J2EE container ...... then you can post your whole code.
Means the the "Server Side Script" and the JavaScript File.
So that I can do test.
Or you can send me your generated HTML file.
Your Client Side Script is HTML or something else?

Debasis Jana
Oct 10 '07 #8
If you are using J2EE container ...... then you can post your whole code.
Means the the "Server Side Script" and the JavaScript File.
So that I can do test.
Or you can send me your generated HTML file.
Your Client Side Script is HTML or something else?

Debasis Jana
Its ASP.net. I am doubting In this part of the code.

Expand|Select|Wrap|Line Numbers
  1. function Major()
  2. {
  3. var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  4.  
  5.  if(deg.selectedIndex != 0)
  6.     {
  7.     AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
  8.     }
  9.  
  10. }
  11. function OnGetMajor(Items)
  12. {
  13.  
  14. var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
  15. if(major.options.length > 0)
  16. {
  17. major.options.length = 0;// to remove previously binded items
  18. }
  19. var o = document.createElement("option");
  20. o.text = "----Select----";
  21. o.value = 0;
  22. major.add(o);
  23. for(i=0;i<Items.length;i++)
  24. {
  25. var options = Items[i].split(",");
  26. var o = document.createElement("option");
  27. o.text = options[1];
  28. o.value = options[0];
  29. major.add(o);
  30. }
  31. }
Oct 10 '07 #9
dmjpro
2,476 2GB
Its ASP.net. I am doubting In this part of the code.

Expand|Select|Wrap|Line Numbers
  1. function Major()
  2. {
  3. var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  4.  
  5.  if(deg.selectedIndex != 0)
  6.     {
  7.     AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
  8.     }
  9.  
  10. }
  11. function OnGetMajor(Items)
  12. {
  13.  
  14. var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
  15. if(major.options.length > 0)
  16. {
  17. major.options.length = 0;// to remove previously binded items
  18. }
  19. var o = document.createElement("option");
  20. o.text = "----Select----";
  21. o.value = 0;
  22. major.add(o);
  23. for(i=0;i<Items.length;i++)
  24. {
  25. var options = Items[i].split(",");
  26. var o = document.createElement("option");
  27. o.text = options[1];
  28. o.value = options[0];
  29. major.add(o);
  30. }
  31. }
Ok let me understand your code.
You have two "Select Box"s ..... "onchange" event of "degree" the major gets cleared and refilled with new one, what you get from Server Side.
This is what happening.
Up to this I am right ?
Now tell me what is being cleared?
Here I am not getting your Point.

Debasis Jana.
Oct 10 '07 #10
I am suspecting that the error is due to the function called in page load, clearing every thing.I try and then let u know . Sorry for disturbing your valuable time.You actually got my question. Thanks for ur suggestions due to which i can trace my errors. I am working on it. I think it will be cleared.
Oct 10 '07 #11
dmjpro
2,476 2GB
I am suspecting that the error is due to the function called in page load, clearing every thing.I try and then let u know . Sorry for disturbing your valuable time.You actually got my question. Thanks for ur suggestions due to which i can trace my errors. I am working on it. I think it will be cleared.
Then check out your "PageLoad" function.

Debasis Jana
Oct 10 '07 #12
Then check out your "PageLoad" function.

Debasis Jana
Sorry Jana error is with my code only.
I am getting Listitems for Major from the selected degree.
During PageLoad this degree is null. so my major selection box got cleared. this what happened. I troubled u alot . Sorry.
Oct 10 '07 #13
dmjpro
2,476 2GB
Sorry Jana error is with my code only.
I am getting Listitems for Major from the selected degree.
During PageLoad this degree is null. so my major selection box got cleared. this what happened. I troubled u alot . Sorry.
What do you mean by this "During PageLoad this degree is null"?
Please Clarify me here.
And post your "PageLoad" function.
Let me have a look here.

Debasis Jana
Oct 10 '07 #14
What do you mean by this "During PageLoad this degree is null"?
Please Clarify me here.
And post your "PageLoad" function.
Let me have a look here.

Debasis Jana
I myself confused a lot. I dont know what was happening. I give you my whole code sir. you please check where i am wrong.But please give me some time to explain u what i'm really doing.
Oct 10 '07 #15
What do you mean by this "During PageLoad this degree is null"?
Please Clarify me here.
And post your "PageLoad" function.
Let me have a look here.

Debasis Jana
I myself confused a lot. I dont know what was happening. I give you my whole code sir. you please check where i am wrong.But please give me some time to explain u what i'm really doing. Is it Time up for you now and I too have got only 15 mins.
Oct 10 '07 #16
dmjpro
2,476 2GB
I myself confused a lot. I dont know what was happening. I give you my whole code sir. you please check where i am wrong.But please give me some time to explain u what i'm really doing. Is it Time up for you now and I too have got only 15 mins.
Right now I am getting confused.
Can't you make me clear?
Actually why "degree" Select Box is null initially?
And you populate the "major" Select Box when you change first one, right?
oh.....I am now getting confused.
Tell me actual scenario and paste the Generated HTML and whole JavaScript.
So that I can have a look at this and make me understand myself.

Debasis Jana
Oct 10 '07 #17
Right now I am getting confused.
Can't you make me clear?
Actually why "degree" Select Box is null initially?
And you populate the "major" Select Box when you change first one, right?
oh.....I am now getting confused.
Tell me actual scenario and paste the Generated HTML and whole JavaScript.
So that I can have a look at this and make me understand myself.

Debasis Jana
Now I will tell u clearly ok.
Degrees[B.A/B.E] Majors for B.A[English,History] for B.E[ECE,EEE,IT]
Now if i Select B.A in degree select box, the Majors for B.A gets binded in Major selectbox dynamically using javascript. Now If i select English as Major and click Save button, the Value English is not carried to Server side[C#.net] where i save the value to database . Some of my colleagues saying me to capture the value in hidden fields and then pass to server side. I know that this is not effective.In generated Html also the major's selected value is 0 having text "--Select--". I will Paste the Generated HTML code also. I value ur suggestion more.

Thank U.
Oct 11 '07 #18
Right now I am getting confused.
Can't you make me clear?
Actually why "degree" Select Box is null initially?
And you populate the "major" Select Box when you change first one, right?
oh.....I am now getting confused.
Tell me actual scenario and paste the Generated HTML and whole JavaScript.
So that I can have a look at this and make me understand myself.

Debasis Jana
My Generated HTML Code
Expand|Select|Wrap|Line Numbers
  1.  <tr>
  2.         <td>
  3.             <span id="ctl00_ContentPlaceHolder1_Label66">Qualification Level</span></td>
  4.         <td>
  5.             <select name="ctl00$ContentPlaceHolder1$ddlQualification" id="ctl00_ContentPlaceHolder1_ddlQualification" onchange="HideQualification();getQualification();" style="width:71%;">
  6.     <option selected="selected" value="0">---Select---</option>
  7.     <option value="38">SSLC</option>
  8.     <option value="39">HSC</option>
  9.     <option value="40">ITI</option>
  10.     <option value="41">DIPLOMA</option>
  11.     <option value="42">NON-ENGG GRADUATE</option>
  12.     <option value="44">ENGG GRADUATE</option>
  13.  
  14. </select>
  15.             <span id="ctl00_ContentPlaceHolder1_Label28" class="ErrorText">*</span></td>
  16.         <td >
  17.             <div id="ctl00_ContentPlaceHolder1_DivlblInstitute"><span id="ctl00_ContentPlaceHolder1_lblInstitute">Institute :</span>&nbsp;</div> </td>
  18.         <td >
  19.            <div id="ctl00_ContentPlaceHolder1_DivtxtInstitute"> <input name="ctl00$ContentPlaceHolder1$txtInstitute" type="text" id="ctl00_ContentPlaceHolder1_txtInstitute" onkeypress="FilterChracterInputs();" style="width:160px;" />
  20.                <span id="ctl00_ContentPlaceHolder1_Label9" class="ErrorText">*</span></div> </td>
  21.     </tr>
  22.      <tr id="ctl00_ContentPlaceHolder1_trdegree">
  23.     <td>
  24.             <span id="ctl00_ContentPlaceHolder1_lblDegree">Degree</span></td>
  25.     <td><select name="ctl00$ContentPlaceHolder1$ddlDegree" id="ctl00_ContentPlaceHolder1_ddlDegree" onchange="Major();" style="width:71%;">
  26.         <option selected="selected" value="0">----Select----</option>
  27.  
  28.     </select>
  29.             <span id="ctl00_ContentPlaceHolder1_Label19" class="ErrorText">*</span></td>
  30.     <td>
  31.             <span id="ctl00_ContentPlaceHolder1_lblMajor">Major</span></td>
  32.     <td>            <select name="ctl00$ContentPlaceHolder1$ddlMajor" id="ctl00_ContentPlaceHolder1_ddlMajor" style="width:87%;">
  33.         <option value="0">----Select----</option>
  34.  
  35.     </select>
  36.             <span id="ctl00_ContentPlaceHolder1_Label16" class="ErrorText">*</span></td>
  37. </tr>
  38. //javascript
  39. function getQualification()
  40. {
  41.     var e = document.getElementById ("ctl00_ContentPlaceHolder1_ddlQualification");
  42.  var qualification = e.options[e.selectedIndex].text; // eg. ENGG GRADUATE
  43.     if(e.selectedIndex != 0)
  44.     {
  45.     AjaxWebService.GetDegree(qualification,OnGetDegree);   //Returns Items[n]
  46.     }
  47. }
  48. function OnGetDegree(Items)
  49. //Items[0] = "44,B.E/B.Tech"
  50. var degri = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  51. var length = degri.options.length;
  52. if(degri.options.length > 0)
  53. {
  54. degri.options.length = 0;
  55. //    var count=0;
  56. //    for ( ; count < e.options.length ;)
  57. //    {  
  58. //    e.remove(count);
  59. //    count = 0;
  60. //    }
  61. }
  62. var o = document.createElement("option");
  63. o.text = "----Select----";
  64. o.value = 0;
  65. degri.add(o);
  66. for(i=0;i<Items.length;i++)
  67. {
  68. var options = Items[i].split(",");
  69. var o = document.createElement("option");
  70. o.text = options[1]; // "B.E/B.Tech"
  71. o.value = options[0]; // "44 "
  72. degri.add(o);
  73. }
  74.  
  75. }
  76. function Major()
  77. {
  78. var deg = document.getElementById ("ctl00_ContentPlaceHolder1_ddlDegree");
  79.  
  80.  if(deg.selectedIndex != 0)
  81.     {
  82.     AjaxWebService.GetMajor(deg.options[deg.selectedIndex].value,OnGetMajor);       
  83.     }
  84.  
  85. }
  86. function OnGetMajor(Items)
  87. {
  88. //Items[0] = "2,ECE"  Items[1] = "3,EEE"
  89. var major = document.getElementById ("ctl00_ContentPlaceHolder1_ddlMajor");
  90. if(major.options.length > 0)
  91. {
  92. major.options.length = 0;// to remove previously binded items
  93. }
  94. var o = document.createElement("option");
  95. o.text = "----Select----";
  96. o.value = 0;
  97. major.add(o);
  98. for(i=0;i<Items.length;i++)
  99. {
  100. var options = Items[i].split(",");
  101. var o = document.createElement("option");
  102. o.text = options[1];
  103. o.value = options[0];
  104. major.add(o);
  105. }
  106. }
Oct 11 '07 #19
dmjpro
2,476 2GB
Now tell me Sudha.............
You don't want to get the Degree List blank initially?
Then you can send me your Server Side Script.
As .Net & J2eeis almost same.
So I can have a look at this.
Don't you have any "<body onload="some_func()">"?
Please let me all these things and send me the Server Side Script.

Debasis Jana.
Oct 11 '07 #20
Now tell me Sudha.............
You don't want to get the Degree List blank initially?
Then you can send me your Server Side Script.
As .Net & J2eeis almost same.
So I can have a look at this.
Don't you have any "<body onload="some_func()">"?
Please let me all these things and send me the Server Side Script.

Debasis Jana.
How to send it is 950 lines. I tried thro' gmail but failed

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. //These js Functions gets called on load
  3.   HideESI()
  4.   HideOldBank()
  5.   HideforDL()
  6.   HideQualification()
  7.   HideExperience()
  8.   Major()
  9.    </script>
Oct 11 '07 #21
dmjpro
2,476 2GB
How to send it is 950 lines. I tried thro' gmail but failed

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" language="javascript">
  2. //These js Functions gets called on load
  3.   HideESI()
  4.   HideOldBank()
  5.   HideforDL()
  6.   HideQualification()
  7.   HideExperience()
  8.   Major()
  9.    </script>
There you can't figure Out.?

Debasis Jana
Oct 11 '07 #22
There you can't figure Out.?

Debasis Jana
Its getting delayed. I try with hidden fields atlast.I knowyou tried to help me a lot.But sorry i am unable to provide you with proper Inputs.sorry frnd.
Oct 11 '07 #23
dmjpro
2,476 2GB
Its getting delayed. I try with hidden fields atlast.I knowyou tried to help me a lot.But sorry i am unable to provide you with proper Inputs.sorry frnd.
Best of Luck with that.

Debasis Jana
Oct 11 '07 #24
Best of Luck with that.

Debasis Jana
hello Jana,
My tries all failed.Hidden field is also failed becoz' on Bodyload call to AjaxWebservice fails . so My select box filled with no options. only this options value i am storing in hidfield which thro's error : option is null. So I finally decided to do it on Server Side. I am very bad in understanding the control flow which swallowed all my time. OK Jana check your PM.
Oct 11 '07 #25
dmjpro
2,476 2GB
hello Jana,
My tries all failed.Hidden field is also failed becoz' on Bodyload call to AjaxWebservice fails . so My select box filled with no options. only this options value i am storing in hidfield which thro's error : option is null. So I finally decided to do it on Server Side. I am very bad in understanding the control flow which swallowed all my time. OK Jana check your PM.
So your Problem is with Ajax Call.

Debasis Jana
Oct 11 '07 #26

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

Similar topics

16
by: Dave Smithz | last post by:
Hi, In summary: I want to a form to submit information via a HTTP POST, however, when using Internet Explorer I want to be able to use the back button and all the information retained....
1
by: john | last post by:
I have two different problems: 1. When the user has clicked on a button that is causing the browser to post back to the server, it could take a little while for the new page to show up. So in...
2
by: Sam | last post by:
I have a custom control (MyTextBox - taken from Microsoft website) that implements the IPostBackDataHandler interface. It is added to the controls collection of a placeholder control during the...
2
by: raffe | last post by:
Hi all! I have a control which represents a user record in my database and a save button. It get's loaded into a placeholder and all the controls like TextBox get bound to the data source. At...
9
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
3
by: Joe | last post by:
Hello All, I am populating an HtmlSelect control's Items property with four list items. The HtmlSelect control is contained in a user control which is dropped into a placeholder on the web form....
2
by: Arthur Dent | last post by:
Hi all, I have a control which i wrote which inherits the asp:dropdownlist control. Works great, all happy. If when using it i try to declaratively add some items, it complains that they are...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
8
by: sudhaMurugesan | last post by:
Hi, Can anyone Help. I have two dropdownlist for qualification and degree. According to the qualification(eg.Diploma,UG,PG) degree gets binded in the dropdownlist. I have done this in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.