0

I have javascript code below, it's working but within Firebug it says

document.form1.element[i] is not defined

and then it works fine

function set_action(){

for (var i=0;i<=3;i++)
{

    if (document.form1.PayType[i].checked == true)

        {
            var billerid = document.form1.billerid[i].value;
                            document.form1.action = billerid +"_mypag.htm";
        }
}

and my html markup is as below

<form name="form1" action="...">
<input name="PayType" type="radio" value="0" id="ultipay" class="radiobtn" checked/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input name="PayType" type="radio" value="1" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>
</select>
<input name="PayType" type="radio" value="2" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input name="PayType" type="radio" value="3" id="ultipay" class="radiobtn"/>
<select name="billerid" class="dropbox">
<option>item1</Option>...
</select>
<input type="button" onclick="set_action()" value="submit">
</form>

I don't know why I am getting this error.

9
  • change form 1 to form in both hml and js ..then check Commented Jan 21, 2013 at 13:34
  • 3
    no, why should he do that? thats the name of his form! Commented Jan 21, 2013 at 13:35
  • 2
    You only have 4 elements, but iterate 7 (or, even worse, 8 - thanks @Marcel) of them? Commented Jan 21, 2013 at 13:36
  • 1
    post your full html and code.. Commented Jan 21, 2013 at 13:41
  • 2
    You should be using document.getElementById, not document.form.xxx. Commented Jan 21, 2013 at 13:42

1 Answer 1

2

If you have only one radio button named PayType, then you need to address it with document.form1.PayType. It is addressed as an array document.form1.PayType[i] iff there are multiple radio buttons with the same name. For instance:

<input name="PayType" type="radio" value="0" id="ultipay0" class="radiobtn" checked="checked" />
<input name="PayType" type="radio" value="1" id="ultipay1" class="radiobtn" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.