ocpaul20 Posted March 30, 2010 Share Posted March 30, 2010 OK, I have tried to make the code as short as possible. The problem is this: if I enter '3+' into the box on the screen and press click, I get back '3 ' (3+space) This is obviously because of the urlencoding on the javascript call but how to get it out with a '+' at the PHP end? I have tried urldecode() and that does not work as I want. Thanks for any help. I am sure it is a simple solution! Paul testscreen1.php =========== <?php // st_quest_editscreen.php ?> <html> <head> <TITLE> test screen 1</TITLE> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <SCRIPT type="text/javascript"> // ================ ajax stuff ===================== function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function getValue() { var val = document.form1.textname.value; sndReqArg(val); } function sndReqArg(val) { var params = 'val='+val; var url = 'testprog1.php'; http.open("POST", 'testprog1.php', true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = handleResponse; // function to handle response http.send(params); } function handleResponse() { if(http.readyState == 4 && http.status == 200) { var response = http.responseText; document.getElementById('qbox').innerHTML=response; // show text return(false); } } </SCRIPT> </head> <body> <div id="formbox" style="float:left;border:1px dashed black;"> <form id="form1id" name="form1" method="post" action="#" > <div style="background-color:blue;color:white;height:20px;" onClick="getValue();return(FALSE);">click</div> <input type="text" name="textname" title="text" value="" /> <div id="qbox" style="border: 1px dotted black;"> return value goes here </div> <!-- end of qbox --> </form> </div> <!-- formbox --> </body></html> testprog1.php ======== <?php // testprog1.php $val = ($_POST['val']); // text $uval = urldecode($val); echo "This is testprog: val = [".$val."] urldecode(val)=[".$uval."]";exit; ?> Quote Link to comment Share on other sites More sharing options...
JustLikeIcarus Posted March 30, 2010 Share Posted March 30, 2010 Try changing your sndReqArg js function to this. function sndReqArg(val) { val = encodeURIComponent(val); var params = 'val='+val; var url = 'testprog1.php'; http.open("POST", 'testprog1.php', true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = handleResponse; // function to handle response http.send(params); } Quote Link to comment Share on other sites More sharing options...
ocpaul20 Posted March 31, 2010 Author Share Posted March 31, 2010 Yes - That works fine. Thank you very much. Paul 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.