views:

38

answers:

2

I have the following code that will check to see if the div text has change and if so then update the text in the mysql table. but when i try and add spaces in the text and it dont allow it to save every thing i have write. Can somebody help me out please

Thank you.

 <script>function save() {   
 var div_sN6VmIGq = $("#64").text();
 var html_sN6VmIGq = $("#64").html();
 var top_sN6VmIGq = $("input#sN6VmIGq_top").val();
 var left_sN6VmIGq = $("input#sN6VmIGq_left").val();
 if(div_sN6VmIGq == "Text Here"){
}else{
 $('#saveupdate').load('modulus/empty/actions.php?act=save_text&pid=1&div_id=64&div_txt='+html_sN6VmIGq+'&randval='+ Math.random());
 }

 }
 </script>
+4  A: 

You need to URLEncode your text:

JavaScript:

var html_sN6VmIGq = escape($("#64").html());
//now use your function for saving the item

PHP:

$decodedVar = urldecode($yourEncodedVarHere);
Bobby
+1  A: 

You probably need to call encodeURI on your somewhat bizarrely named variables:

$('#saveupdate').load('modulus/empty/actions.php?act=save_text&pid=1&div_id=64&div_txt='+encodeURI(html_sN6VmIGq)+'&randval='+ Math.random());

Also, note that the id 64 is invalid, per this comment from W3Schools:

[ids must] begin with a letter A-Z or a-z followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

Dominic Rodger
s/uriEncode/encodeURI/
softcr
@softcr - thanks, fixed.
Dominic Rodger