Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Jquery problem

  1. #1
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts

    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........

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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>\
    ');

  • #3
    Regular Coder
    Join Date
    May 2011
    Posts
    303
    Thanks
    29
    Thanked 0 Times in 0 Posts
    Well that didn't help, any other ideas...

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    What is the error then?

  • #5
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •