JavaScript: change function(this) to function(this.id) -


i have javascript function open kcfinder file manager url textbox.

js:

<script type="text/javascript">  function openkcfinder(field) {     window.kcfinder = {         callback: function(url) {             field.value = url;             window.kcfinder = null;         }     };     window.open("http://localhost/cms/kc/browse.php?type=video&dir=files/public", "kcfinder_textbox",         "status=0, toolbar=0, location=0, menubar=0, directories=0, " +         "resizable=1, scrollbars=0, width=800, height=600"     ); }  </script> 

html:

<input id="video" onclick="openkcfinder(this)" class="form-control" type="text" name="video" placeholder="add video"> // need change openkcfinder(this.id)  <input id="audio" onclick="openkcfinder(this)" class="form-control" type="text" name="video" placeholder="add video"> // need change openkcfinder(this.id) 

now need change (this) (this.id) change type of open url. ie: if textbox/input id="video" type=video or if textbox/input id="audio", type=audio.

how change function need?

demo kcfinder textbox

you can way:

<script type="text/javascript">  function openkcfinder(field) {     window.kcfinder = {         callback: function(url) {             field.value = url;             window.kcfinder = null;         }     };     if (field.id === 'video') {         window.open("http://localhost/cms/kc/browse.php?type=video&dir=files/public", "kcfinder_textbox",             "status=0, toolbar=0, location=0, menubar=0, directories=0, " +             "resizable=1, scrollbars=0, width=800, height=600"         );     }     else if (field.id === 'audio') {         // open else     }     else {         // handle unknown     } }  </script> 

or if you're sure ids, do

window.open("http://localhost/cms/kc/browse.php?type=" + field.id + "&dir=files/public", "kcfinder_textbox",     "status=0, toolbar=0, location=0, menubar=0, directories=0, " +     "resizable=1, scrollbars=0, width=800, height=600" ); 

you may interested in mdn's documentation of htmlinputelement, describes properties have this in field.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -