javascript - How to clear text area? -


i have problem of clearing out of text area in application. app has 2 methods of getting specific data format: searching online database , using javascript library.

first method: user types chemical name in text field , presses "search" button. if requested compound in database, proper format displayed in text area.

second method: if name not found in database, user can use js library generate proper format displayed in same text area.

if user uses database first, text area contains generated data database can replaced data generated js library if user decides use it. problem if text area has data generated js library cannot replaced data database when first method used. don't know how clear text area containing data (generated js library) before inserting data database. sorry if still sounds confusing.

here javascript code:

<script>   var sketcher = new chemdoodle.sketchercanvas('sketcher', 400, 300, {useservices:true});   var mol = sketcher.getmolecule();   var molfile = chemdoodle.writemol(mol);    function myfunc($data)  {   document.getelementbyid('txt_area').value = $data   return false   } </script>  <span onclick="myfunc(chemdoodle.writemol(sketcher.getmolecule()));"  <button href='javascript:void(0)'; type="submit" id="get_mol">get mol</button> </span> 

jquery/ajax:

$('#search').on('click', function()    {         chemical = $('#chemical').val();             $.ajax({     type: "get",     url: "/_get_smiles",     data : { 'chemical': chemical},     success: function(data)     {             $('#txt_area').text(data.smiles);     },     error: function(error)      {     console.log(error)     }    });     }); 

html:

<input type="text" id="chemical" size="40"> <button type="submit" id="search" value="search">search</button> <textarea id="txt_area" name="smiles_mol" rows="28" cols="49"></textarea> 

to clear text area methods below unsuscessfully:

$('#txt_area').text = ""; $('#txt_area').html = ""; $("#txt_area").attr("value", ""); 

method $('#txt_area').val(""); clears text area prevents inserting data database. comments , suggestions highly appreciated!

i think need change jquery/ajax portion use this:

$('#txt_area').val(data.smiles); 

however it's bit confusing how parts relate 1 since seem have 2 different pieces of javascript , 2 pieces of html haven't written them together. how file structured? if 1 supposed fallback other, feels should done automatically.

edit - this, if i'm understanding correctly:

$('#search').on('click', function() {       chemical = $('#chemical').val();           $.ajax({     type: "get",     url: "/_get_smiles",     data: {       'chemical': chemical     },     success: function(data) {       if (data.smiles) {         $('#txt_area').val(data.smiles);       } else {         $('#txt_area').val(chemdoodle.writemol(sketcher.getmolecule()));       }     },     error: function(error) {       console.log(error);       $('#txt_area').val(chemdoodle.writemol(sketcher.getmolecule()));     }   });   }); 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -