0

i found this javascript is called by a button but i want it to be onload at the same time , when button click it will call this javscript as well but i not sure how? hopefully anyone of you can help out

 function AddFileUpload()
        {
             var div = document.createElement('DIV');
             div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + '" type="file" /><input id="Button' + counter + '" type="button" value="Remove" onclick = "RemoveFileUpload(this)" />';
             document.getElementById("FileUploadContainer").appendChild(div);
             counter++;
        }
2
  • Might be useful to see your onClick Listener to figure out what's going on/wrong. Commented Feb 2, 2012 at 10:04
  • Note that the solidus /> is most probably incorrect. Just omit that additional slash. This is most probably not the cause of your original problem, though. I suggest to use FireBug or any similar debugger to see what's going wrong (perhaps there is no FileUploadContainer element or counter is not defined ....). Commented Feb 2, 2012 at 10:21

2 Answers 2

1
<body onload="AddFileUpload();">
Sign up to request clarification or add additional context in comments.

1 Comment

If that doesn't work then I bet you have some other problem with your code. Try adding an alert("AddFileUpload called"); at the beginning of your function as a simple debugging method.
1

You can call javascript on load using jquery.

$(document).ready(function() { var div = document.createElement('DIV'); div.innerHTML = ''; document.getElementById("FileUploadContainer").appendChild(div); counter++; });

8 Comments

somewhat overkill to use JQuery for such a simple task.
i try but dont know why it dont anything
you can also put your code in this section $(function() { // Handler for .ready() called. });
whic jquery js file are you refering
add this in head <script src="code.jquery.com/jquery-latest.js"></script>.
|

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.