Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-23-2012, 02:04 AM   PM User | #1
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
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........
Chris-2k is offline   Reply With Quote
Old 08-23-2012, 12:06 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
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>\
');
devnull69 is offline   Reply With Quote
Old 08-23-2012, 01:26 PM   PM User | #3
Chris-2k
Regular Coder

 
Join Date: May 2011
Posts: 303
Thanks: 29
Thanked 0 Times in 0 Posts
Chris-2k is an unknown quantity at this point
Well that didn't help, any other ideas...
Chris-2k is offline   Reply With Quote
Old 08-24-2012, 08:18 AM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
What is the error then?
devnull69 is offline   Reply With Quote
Old 08-24-2012, 08:20 AM   PM User | #5
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 530 Times in 524 Posts
devnull69 will become famous soon enough
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.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:53 AM.


Advertisement
Log in to turn off these ads.