views:

58

answers:

6

i have a string like

var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';

I want to get only the value of that input box which is stored in str as Beauty is Fake

is there anyway to get it?

+6  A: 
$(str).val(); // this would do it...

have a look

Reigel
+5  A: 
var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';
alert($(str).attr('value'));
// or
alert($(str).val());
ILMV
A: 

You can create the element and access the attribute after that:

  • var myInput = document.createElement(str);
  • alert(myInput.value);
GôTô
`document.createElement(str)` - str should be a valid string html tag name. your answer will raise `Uncaught Error: INVALID_CHARACTER_ERR: DOM Exception 5`
Reigel
My mistake, I had in mind something like this (which is not as simple as jQuery solution) `var div = document.createElement('div'); div.innerHTML = '<input type="text" id="se_tbox" value="Beauty is Fake" />'; alert(div.getElementsByTagName('input')[0].value);`
GôTô
+1  A: 

you can use this:

$(str).val();
bruno
why would someone downvote this? its the same as the 5 and 4 voted answers above!
Thomas Clayson
+1  A: 

You can use jquery

$('<input type="text" name="se_tbox" value="Beauty is Fake" />').val()

or regular expression

'<input type="text" name="se_tbox" value="Beauty is Fake" />'.match(/value="([^"]*)"/)[1]
jcubic
A: 

You shouldn't stringify your HTML to process it.
But if you have to, you can use a regexp to get the value:

var val = '<input value="Beauty is Fake" />'.match(/value="([^\"]+)/)[1];
Mic