CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   Jquery problem (http://www.codingforums.com/showthread.php?t=271179)

Chris-2k 08-23-2012 02:04 AM

Jquery problem
 
hi.

when i add this to my .js file:
PHP Code:

// Add File Input
function addInput(){
    $(
"#localUpload").append('    <div class="file_input_div">
        <input id="fileName" class="file_input_textbox" placeholder="No File Selected..." readonly="readonly" />
        <input type="button" value="Browse..." class="file_input_button" /> 
        <input type="file" name="image_upload[]" id="file_upload" class="file_input_hidden" onchange="javascript: this.form.fileName.value=((this.value.replace(/^.*[\/\\]/g, "")).split("..",2));" />
    </div>
'
);


it says theres an error, why........

devnull69 08-23-2012 12:06 PM

You cannot just include line breaks inside a string literal. You'll have to escape them using the \ backslash character.

Code:

    $("#localUpload").append('    <div class="file_input_div">\
        <input id="fileName" class="file_input_textbox" placeholder="No File Selected..." readonly="readonly" />\
        <input type="button" value="Browse..." class="file_input_button" /> \
        <input type="file" name="image_upload[]" id="file_upload" class="file_input_hidden" onchange="javascript: this.form.fileName.value=((this.value.replace(/^.*[\/\\]/g, "")).split("..",2));" />\
    </div>\
');


Chris-2k 08-23-2012 01:26 PM

Well that didn't help, any other ideas...

devnull69 08-24-2012 08:18 AM

What is the error then?

devnull69 08-24-2012 08:20 AM

You are using the backslash inside a javascript string to handle regular expression escaping, but it is already used for javascript character escaping. So you will have to replace every \ backslash inside the regular expression with a double backslash \\ which will escape the backslash to be used for the regex.


All times are GMT +1. The time now is 11:42 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.