Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the value of the text box from a HTML Coded String

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?

like image 632
Rajasekar Avatar asked Sep 24 '10 08:09

Rajasekar


People also ask

How do I get the value of an html input?

Use document. getElementById(id_name) to Get Input Value in JavaScript. We give the id property to our Dom input element, and then use document. getElementById(id_name) to select DOM input element, you can simply use the value property.


3 Answers

$(str).val(); // this would do it...

have a look

like image 91
Reigel Avatar answered Oct 20 '22 09:10

Reigel


var str='<input type="text" name="se_tbox" value="Beauty is Fake" />';
alert($(str).attr('value'));
// or
alert($(str).val());
like image 37
Ben Everard Avatar answered Oct 20 '22 07:10

Ben Everard


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]
like image 45
jcubic Avatar answered Oct 20 '22 07:10

jcubic