I was wondering if anyone could give some advice on getting all the text in a form input:text field up until the first whitespace character
Basically I am inputting an address like so 5575 Fake street New York USA and I need to get the 5575 from the form and add it to another form
Any ideas
*cheers
Maboroshi
[solved] jquery get text up until first space in form field
Re: jquery get text up until first space in form field
Try this
Input the text you posted
Code: Select all
<!DOCTYPE html>
<html>
<head>
<style>
p { color:blue; margin:8px; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<input type="text" value="some text"/>
<p></p>
<script>
$("input").keyup(function () {
var value = $(this).val();
var substr = value.split(" ");
$("p").text(substr[0]);
}).keyup();
</script>
</body>
</html>
Code: Select all
5575 Fake street New York USA
"The best place to hide a tree, is in a forest"
Re: jquery get text up until first space in form field
Thanks Cats! Worked great I ended up using
*cheers
Code: Select all
<script>
$("#address").keyup(function () {
var value = $(this).val();
var substr = value.split(" ");
$("#listing_address_number").val(substr[0]);
}).keyup();
</script>