0

I'm new to create wordpress widget,I want to create a widget which will upload an image and display it on the site's front page,for the sake of that thing i'm writing following code but javascript is not running properly in my code,following code is written in class WP_My_Widget and in file default-widgets.php,actually code of javascript is not running when I try to alert the count of loaded files it simply show me 0.

public function form( $instance ) {
// outputs the options form on admin
?>
<br/>

Please Enter The URL of Leading Site: <input type='text' name='url' id='url'/><br/>
Upload new image: <input type='file' name='images' id='images'><br/>
<br/><a href='javascript:void(0);' id='myid' onclick='abc();'>Proceed Uploaded File!</a>
<script>
    function abc(myurl){
    myLocalFiles = document.getElementById('images');
    len = myLocalFiles.files.length;
    alert(len);             
    }        
</script>       
<?php              
}

1 Answer 1

1

you should try

myLocalFiles = document.getElementById('images').files;
len = myLocalFiles.length;
alert(len); 

check this fiddle

I think its not a wordpress issue.

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

Comments

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.