I am trying to get specified value from a textarea.
Html:
<textarea name="pull">input type="text" name="bd" value="bd" input type="text" name="bd1" value="bd2" input type="text" name="bd2" value="bd3"
</textarea> <br/>
<input type="button" onclick="pulldata()" value="Button" />
<br/>
<textarea name="tor" id="tor"></textarea>
JS
<script language="javascript">
function pulldata() {
var raw=document.getElementsByName('pull')[0].value;
var jqn=raw.split('name=\"')[1].split('\" ')[0];
var vals=raw.split('value=\"')[1].split('\" ')[0];
document.getElementById('tor').value=jqn+'\: \"'+vals+'\"\,';
};
</script>
This code Seems to work the result i get is;
bd: "bd",
But i want to get all name=(.+?) & value=(.+?)
from the textarea, without using (name=\\")[1] [2]... [n]
loop method is fine by me. How do i do it?
Split raw
by "input "
, then loop through it and use your logic:
var inputs = raw.split("input ")
for(var i = 0; i < inputs.length; i++) {
// Do what you wanna do, then push it to an array
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.