hello guys, i hope everyone reader has abit know how of ajax. I am stuck at the position where I am trying to do nested ajax calls. The scenario is: My main page has an iframe, which loads the content (dozen of drop down lists) through ajax, and than at one of the Lists i have an onchange event which again loads a <div> through ajax. The second ajax call doesnt seem to work after such a long time. One more question regarding this, How can I get the value of selected option of the deop-down list which is loaded through ajax call ? thanks
I mean to call from an onchange event of Dropdown list which is itself generated through Ajax. Lets suppose, The First List is of Countries List1: Albania, Croatia, ,.... USA, Zimbabwe On selecting any country, the ajax call will return another set of lists e.g. State/City, ZipCode, Address ,etc. Lets say, it returns 2 lists, call them List 2 & List 3 List2: California, Denver, NewYork ... List 3: 1234, 5678, 3153, ... When I select California, I need to trigger an ajax call to load something else, but here, the <select onchange=jsFUNCTION(this.value)><option></></> onchange function is not triggered to call the js function. I want to get the value of List2 selection, either I can use ajax, or assign the selection value to a hidden field. But both doesnt seem to work. If I assign the value of List2 selected-index to a hidden field at the same page, the parent page, couldnot retrieve it using php POST variable e.g. <input class="Hidden" id="hiddentext" value="" > JS(){ // hiddentext.value = list.option.value } <?php $value = $_POST['hiddentext']; //it doesnt retreive the right value ?>
Using a hidden field is the right way to do it - I've done this before and it works fine for me - it sounds like you may not be referencing your elements correctly. I normally pass the value to onchange doing:- onchange="javascript:updateField(options[selectedIndex].value);" Then for the function I do something like function updateField(p_selected_value) { var hiddenbox = document.getElementById('hiddentext').value; hiddenbox.value=p_selected_value; }
yes, i have solved the problem using hidden fields as u mentioned above. BUT, its not the right way, as i have lots of fields which I will be retrieving using hidden fields. And it will make the whoe page slow..... any fast solution if this kind of problem appears and u have a lot of fields to get their value !!!
why does it make the page slow? how many fields are we talking about? it's just setting a variable - it's not an intensive process
i have 30 to 40 fields for which i need the value like this...so i have to make 30-40 hidden text fields, which will load and get hidden. so making an overhead....i am updating the values of these fields on a single function...anyway....as long as its working its fine!!!
the only way i can think of doing it without creating those hidden fields is to loop through all the fields and create a big string of ?var1=val1&var2=val2&... and append that string to the form action url via GET, but then you will have this data showing up on the browser bar after the user submits.