millercj Posted December 11, 2008 Share Posted December 11, 2008 Running an Ajax script and the number of parameters i'm passing is dynamic. My parameter string is generated and sent to the PHP via the following function: function save(numStd){ //Find Selected Class var all = document.all ? document.all : document.getElementsByTagName('*'); var elements = new Array(); for (var e = 0; e < all.length; e++) if (all[e].className == 'active') var currentClass=all[e].id; var sendParams=escape(numStd)+"¶m1="+escape(currentClass); var paramCounter=2 for(var i = 1; i <= numStd; i++){ window['lNameSave'+i] = document.getElementById("LastName"+i).value; window['fNameSave'+i] = document.getElementById("FirstName"+i).value; window['ageSave'+i] = document.getElementById("Age"+i).value; sendParams =sendParams+"¶m"+paramCounter+"='"+escape(window['lNameSave'+i])+"'"; paramCounter++; sendParams =sendParams+"¶m"+paramCounter+"='"+escape(window['fNameSave'+i])+"'"; paramCounter++; sendParams=sendParams+"¶m"+paramCounter+"="+escape(window['ageSave'+i]); paramCounter++; } var urlNewStd = "/phpscripts/saveNewStd.php?param="; http.open("GET", urlNewStd + sendParams, true); document.getElementById("studentresult").innerHTML="<img src='/images/ajax-loader.gif' style='margin:50px 0 0 110px;'/>"; http.onreadystatechange = handleHttpResponseNewStd; http.send(null); } if I input two records to send as parameters this is an example of what urlNewStd + sendParams looks like: /phpscripts/saveNewStd.php?param=2¶m1=4A¶m2='Williams'¶m3='Robin'¶m4=55¶m5='Moore'¶m6='Demi'¶m7=45 once it is in the PHP I can only access the first parameter which in the example would be "2" I'm trying the get the Parameters in PHP via: $variable= urldecode($_GET['param1']); any ideas? Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted December 11, 2008 Share Posted December 11, 2008 What is the problem? Quote Link to comment Share on other sites More sharing options...
millercj Posted December 11, 2008 Author Share Posted December 11, 2008 I can only access the first parameter, none of the other ones have a value Quote Link to comment Share on other sites More sharing options...
DeanWhitehouse Posted December 11, 2008 Share Posted December 11, 2008 that code doesn't make sense to me, you are sending each var on it's own instead of sending them all together. Take a look at http://www.codeguru.com/forum/showthread.php?t=421822 Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 11, 2008 Share Posted December 11, 2008 lol your making it wayyyyyyyyyyyy to complicated with all the params, this is the wrong section btw. Quote Link to comment Share on other sites More sharing options...
millercj Posted December 11, 2008 Author Share Posted December 11, 2008 how would you propose it's done? Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 11, 2008 Share Posted December 11, 2008 how would you propose it's done? Depends on what I'm using it for. As stated your script doesn't send the params all at once Quote Link to comment Share on other sites More sharing options...
millercj Posted December 11, 2008 Author Share Posted December 11, 2008 What the interface is--is a window in which the user can add students to respective classes. The user creates as many "new student" fields (first name, last name, age) as they wish by clicking a button that number of times (so the number of parameters needed is dynamic). Then then the data in those fields needs to be passed via ajax to be inserted into a sql table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.