broadbeach
09-13-2011, 04:44 AM
Hi all
I have relatively easy task I need to accomplish but as per usual I have very little idea of how to do it. I have done a google search to no avail.
Basically I need to:
1. Pull a value from inside a div
<div id="number">(invoice #1017)</span>
2. Populate a form input field with that value.
Does this make sense? If not let me know if you need any more info.
Thanks
xelawho
09-13-2011, 04:57 AM
not sure about your </span> tag there, but anyway...
<body>
<div id="number">(invoice #1017)</div>
<input type="text" id="result"></input>
<script type="text/javascript">
document.getElementById("result").value=document.getElementById("number").innerHTML;
</script>
</body>
Blazer2000x
09-13-2011, 05:02 AM
Well, here's a function to pull, parse, and return the first number encountered:
function parseDiv(id) {
var d = document.getElementById(id).innerHTML;
var ints ={0:true,1:true,2:true,3:true,4:true,5:true,6:true,7:true,8:true,9:true};
var start = 0;
for(x in d) if(d[x] in ints) { start = x; break; }
return parseInt(d.substring(start,d.length));
}
Of course, that assumes you've got javascript to work it into.
Just pass the string value of the id of the div with the number in it.
Hope that helps!
broadbeach
09-13-2011, 05:15 AM
not sure about your </span> tag there, but anyway...
<body>
<div id="number">(invoice #1017)</div>
<input type="text" id="result"></input>
<script type="text/javascript">
document.getElementById("result").value=document.getElementById("number").innerHTML;
</script>
</body>
Thanks for your help, this is exactly what I needed.
xelawho
09-13-2011, 02:36 PM
you're welcome.
if you want to get rid of the brackets you can do this:
<body>
<div id="number">(invoice #1017)</div>
<input type="text" id="result"></input>
<script type="text/javascript">
str=document.getElementById("number").innerHTML;
document.getElementById("result").value=str.slice(1,str.length-1)
</script>
</body>
or this:
<body>
<div id="number">(invoice #1017)</div>
<input type="text" id="result"></input>
<script type="text/javascript">
document.getElementById("result").value=document.getElementById("number").innerHTML.replace(/[(|)]/g,"");
</script>
</body>