How do I remove this spacing from the textbox. PS: I've checked and confident that my variable does not contain any spacing to begin with.
At firstpage.php, I changed the php variable '$pcodevar' to javascript variable 'pcode' and pass it to upload.php.
function upload() {
var pcode=" <?php echo $pcodevar;?>";
var uploadwindow = window.open("upload.php", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
uploadwindow.pcode= pcode;}
At upload.php, i wrote a script to receive the variable and identify it as fid_17.
<script language="javascript" type="text/javascript">
function initInput()
{
document.forms[0].fid_17.value = pcode;
}
</script>
Next still at upload.php,
<body onLoad="initInput()">
<form name="form1" method="post" action="upload.php" enctype="multipart/form-data"/>
Project ID:
<input name="fid_17" id="fid_17" value=""/><br><br>
Upload File:
<input type="text" name="t" placeholder="File name" />
<input class="button blue" type="submit" name="upload" value="Upload/View!"/><br>
<input type="file" name="f" /><br>
</form>
Thank you for helping!
I think you should just trim the 'pcode' value before setting value. Try to use trim
function in php and js. Also remove the leading space when setting $pcodevar(see below)
var pcode = "<?php echo trim($pcodevar);?>";
pcode = pcode.trim();
I would suggest using .trim() on the "pcode". Please see, http://www.w3schools.com/jsref/jsref_trim_string.asp
If you don't need to support older browsers (ie IE8), please avoid using regular expression way
You should use trim in PHP and JavaScript sides.
function upload() {
var pcode="<?php echo trim($pcodevar);?>";
pcode = pcode.trim();
var uploadwindow = window.open("upload.php", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
uploadwindow.pcode= pcode;}
trim out the value you assigned to fid_17:-
document.getElementById('fid_17').value= pcode.trim()
also console out the value of pcode. hope this will help
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.