0

I am using valums-file-uploader plugin. It allows me to upload files using ajax. I have a problem with it. I have the following script-

<input type="text" id="Gaurav" name="Gaurav" />
<script src="fileuploader.js" type="text/javascript"></script>
<script>
    function createUploader(){
        var uploader = new qq.FileUploader({
            element: document.getElementById('file'),
            action: 'do-nothing.php',
            params:{param: document.getElementById('Gaurav').value},
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            minSizeLimit: 1,
            debug: false
        });
    }

    // in your app create uploader as soon as the DOM is ready
    // dont wait for the window to load  
    window.onload = createUploader;     
</script>

In it, I want to set the value of param entered by the user. The code is working properly for default value of Gaurav, but didn't work for user inputted value.

2
  • 2
    The uploader is created with that value when the window loads, it doesn't magically change when the input value changes Commented Jul 26, 2012 at 15:21
  • Which library/framework/plugin is that? Please link to it / tag your question - it does not seem to be jQuery.ajax. Commented Jul 26, 2012 at 15:23

2 Answers 2

3

You need to call createUploader after the user has entered a value. This code is 'fixing' the param value as soon as the window loads.

You may have a button click event or something - call it from that and it will take the value at that time...

Sign up to request clarification or add additional context in comments.

1 Comment

On the place of window.onload, I wrote-var g= document.getElementById('Gaurav'); g.onblur= creatUploader;
2

You set a param to your function (the value you want to push) and call the function when the user writes something inside the input. *The param is in fact optional because your function gets the value from the input itself but it is more efficient to pass the argument as you skip the DOM search.

<input type="text" id="Gaurav" name="Gaurav" onchange="createUploader($(this).val())" />
<script src="fileuploader.js" type="text/javascript"></script>
<script>
    function createUploader(value){
        var uploader = new qq.FileUploader({
            element: document.getElementById('file'),
            action: 'do-nothing.php',
            params:{param: value,
            allowedExtensions: ['jpg', 'jpeg', 'png', 'gif'],
            minSizeLimit: 1,
            debug: false
        });
    }

    // in your app create uploader as soon as the DOM is ready
    // dont wait for the window to load  
    window.onload = createUploader($("#Gaurav").val());     
</script>

1 Comment

It s also set on the onchange event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.