Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Variables from Dynamic HTML

Status
Not open for further replies.

scripter50

IS-IT--Management
Dec 9, 2002
35
US
I am having trouble accessing variables that are in javascript - dynamically generated html forms. Typically I am writing a script with innerHTML generating radio or checkboxes, placed in <div> or <span> tags on my html page. My trouble is accessing the variables via hidden fields - I can't seem to get them to read.

<script>
function tariffText() {
document.all.dynText.innerHTML = &quot;<table><tr><td>
<input type=&quot;radio&quot; name=&quot;tariff&quot; value=&quot;175&quot; checked><br>
<input type=&quot;radio&quot; name=&quot;tariff&quot; value=&quot;128&quot;>
</td></tr></table>&quot;;
}
</script>

in my accessing the value...
function checkTariff(){
var i=0;
tariffChecked=-1;
for(i=0;i<document.formname.tariff.length; i++}
if(document.formname.tariff.checked) {
tariffChecked = i;
break;
}
}

passing the value to the hidden field...
function validateForm(){
if (!checkTariff()) return;
document.formname.tariff.value = + document.formname.tariffName.value;
document.formname.submit();
}
}

in my html page:
<input type=&quot;hidden&quot; name=&quot;tariffName&quot; value = &quot;&quot;>
....<span id=&quot;dynText&quot;></span>

Why can't I access the variables???
thanks in advance...
 
This code sould work for what you want.

<html>
<head>
<script>
function tariffText() {
document.all.dynText.innerHTML = &quot;<table><tr><td><input type='radio' name='tariff' value='175' checked><br><input type='radio' name='tariff' value='128'></td></tr></table>&quot;;
}

function checkTariff() {
var i=0;
tariffChecked = -1;
for (i=0; i < document.formname.tariff.length; i++) {
if(document.formname.tariff.checked) {
tariffChecked = i;
break;
}
}
}

function validateForm() {
alert(document.formname.tariff);
if (!checkTariff())
return;

document.formname.tariff.value = + document.formname.tariffName.value;
document.formname.submit();



}

</script>
</head>

<body>
<form name=&quot;formname&quot; method=&quot;get&quot; action=&quot;#&quot; onSubmit=&quot;validateForm();&quot;>
<input type=button name=d value=&quot;click me&quot; onClick=&quot;tariffText();&quot;>
<br>
<input type=&quot;hidden&quot; name=&quot;tariffName&quot; value = &quot;&quot;>
<span id=&quot;dynText&quot;></span>
<input type=submit value=submit>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top