views:

41

answers:

3
$("#txtcode").autocomplete({
  minLength: 1,
  source:  "/AC/student.php?searchMode=''&Stno="+$("#txtcode").attr("value"),
  select: function(event, ui) 
  {
    var label= ui.item.label;
    var value= ui.item.value;
    var stuArr = label.split('-');               
    alert(stuArr [1]);
    $('#tx_stname').val( stuArr [1].replace(/\$/g, ""));

  }
});

In the above code when I say alert(stuArr [1]);.

I am getting the font tag <font size='1' color='green'>ABCDERT(Student name)</font> from the server side script.

How do I remove the font tags and put the "ABCDERT" name in the textbox ($('#tx_stname'))?

+3  A: 

You can wrap it to treat it as an element and use .text() like this:

$('#tx_stname').val($(stuArr[1]).text());
Nick Craver
@nick:Iam able to get the value That i was expecting but the value in the textbox still conatains the '$$'SOMEVALUE'' which i was replacing with this statement ( stuArr [1].replace(/\$/g, ""));.How do i replace the '$$'SOME value'' in the textfield $('#tx_stname').val($(stuArr[1]).text.replace(/\$/g, "")); which is returning error
Someone
@Someone - You need parenthesis on the `.text()` in that call then you're all set :)
Nick Craver
Thanks It worked out .But How do i replace the ' SOMEValue '.How do i replace the Single Quotes for the 'SOME Value'
Someone
@Someone - Which text field, are you talking about `tx_stname` or `txtcode` that you're using for the URL?
Nick Craver
@Nick: tx_stname text field >Iam getting the Value as 'SOMEVEALUE'.I have to remove the single quotes before and after the somevalue.How do i do it in the replace replace(/\$/g, "")
Someone
@Someone - The replace would look like this: `.replace(/\'/g, "")`
Nick Craver
@nick:I could not replace with this statement $('#tx_stname').val($(stuArr [1]).text().replace(/\'$/g, ""));I have to replace two Things 1)"$" 2)'(single quotes)
Someone
@Someone - Ah, in that case, `.replace(/(\'|\$)/g, "")`
Nick Craver
@NICK :Thanks It worked out
Someone
@nick: $('#tx_stname').val($(stuArr[1]).text().replace(/(\'|\$)/g, ""));.In the above statement i wanted to remove the White space which is occuring for the text box value . i have tried to use trim() to remove white space it is returning error and i have tried using in the regular expression such as "replace(/(\'|\$|\ )/g, "") for removing spaces which did not work out I mean it is replacing all the spaces with in the value.How do i trim
Someone
A: 

Try: alert($(stuArr[1]).html());

For example:

<html>
  <body>
    <script src="http://code.jquery.com/jquery-1.4.2.min.js"&gt;
    </script>

    <script>
      var s = "<font>abc</font>";
      alert($(s).html());
    </script>
</html>
mbrevoort
+1  A: 

Try this:

$('#tx_stname').val( stuArr [1].replace(/<[^>]+>/g, ""));
Serplat