cubicalmonkey
asked on
How to parse text between HTML tags and set to variable value
Hello,
Using Javascript, how could I obtain everthing between the input tags and set it as a variable value?
The name and value attributes are dynamic and can change.
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198301>The modem is <b>ONLINE</b> ALL LEVELS WITHIN SPEC</b>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198302>Modem <b>Offline</b> - (<b>SNMP Query failed</b>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198303>A different message is listed
For example, I want to parse out "The modem is <b>ONLINE</b> ALL LEVELS WITHIN SPEC</b>"
Using Javascript, how could I obtain everthing between the input tags and set it as a variable value?
The name and value attributes are dynamic and can change.
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198301>The modem is <b>ONLINE</b> ALL LEVELS WITHIN SPEC</b>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198302>Modem <b>Offline</b> - (<b>SNMP Query failed</b>
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198303>A different message is listed
For example, I want to parse out "The modem is <b>ONLINE</b> ALL LEVELS WITHIN SPEC</b>"
you could fix this up by closing the input tags and then putting the contents in a span tag next to them
then your solution would look like this:
<html>
<head>
<script type="text/javascript">
function getNxtInnerHTML(obj)
{
var s = obj.nextSibling.innerHTML;
alert(s);
}
</script>
</head>
<body>
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t his); doSubmit()' NAME=default_Q1_2_1927 VALUE=198301/><span>The modem is <b>ONLINE</b> ALL LEVELS WITHIN SPEC</b></span>
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t his); doSubmit()' NAME=default_Q1_2_1927 VALUE=198302/><span>Modem <b>Offline</b> - (<b>SNMP Query failed</b></span>
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t his); doSubmit()' NAME=default_Q1_2_1927 VALUE=198303/><span>A different message is listed</span>
</body>
</html>
then your solution would look like this:
<html>
<head>
<script type="text/javascript">
function getNxtInnerHTML(obj)
{
var s = obj.nextSibling.innerHTML;
alert(s);
}
</script>
</head>
<body>
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t
<INPUT TYPE=RADIO OnClick='getNxtInnerHTML(t
</body>
</html>
ASKER
My problem becomes more complicated... This form is dynamically generated by a java applet (which I'm not familiar with nor have full control over) so adding <span> </span> after the <input> tag isn't really an option for me. Unless its possible to do after the page loads? Something like find/replace???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oh, we don't need this in there anymore:
function getNxtInnerHTML(obj)
{
var s = obj.nextSibling.innerHTML;
alert(s);
}
function getNxtInnerHTML(obj)
{
var s = obj.nextSibling.innerHTML;
alert(s);
}
ASKER
Thank you!
This is exactly what I was looking for!
This is exactly what I was looking for!
ASKER
I'm having a problem getting this code working in IE.
It works perfectly in Firefox but I returns an unterminated constant string constant.
it seems IE does not like the " on this line.
inputs[i].onclick = new Function("var answers=('"+megatrim(newSp an.innerHT ML.toStrin g())+"');p opinframe( answers);d oSubmit(); ");
I've posted another question for help resolving this problem
https://www.experts-exchange.com/questions/22864952/unterminated-string-constant-on-in-IE-for-complex-function.html
It works perfectly in Firefox but I returns an unterminated constant string constant.
it seems IE does not like the " on this line.
inputs[i].onclick = new Function("var answers=('"+megatrim(newSp
I've posted another question for help resolving this problem
https://www.experts-exchange.com/questions/22864952/unterminated-string-constant-on-in-IE-for-complex-function.html
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198301/>
or you can write it like this:
<INPUT TYPE=RADIO OnClick='doSubmit()' NAME=default_Q1_2_1927 VALUE=198301></input>
as it is, where are the closing tags for your input tags? you don't have any... that's naughty.