-2

On my first page I have two radio buttons, each with a value. When the link is clicked to go to page 2, the following for loop runs and gets the value of the checked button. (That script works, I've tested it):

function func1(){
    var info = document.Information;
    for(var i1 = 0;i1 < info.length;i1++){
        if (info.elements[i1].type == "radio" && info.elements[i1].checked) {
        ordertype = info.elements[i1].value;
        alert(ordertype);       
        }
    }
}

The variable ordertype is declared outside of the function. On page two I have this function run on a button click:

function func2(){
     alert(ordertype);  
}

ordertype is now undefined... How can I correctly pass the variable to the new function?

Wilson
  • 8,570
  • 20
  • 66
  • 101

1 Answers1

0

If using javascript... you could pass via querystring:

function func1() {

        var info = document.Information;

        for (var i1 = 0; i1 < info.length; i1++) {
            if (info.elements[i1].type == "radio" && info.elements[i1].checked) {
                ordertype = info.elements[i1].value;
                break;
            }
        }
        location = 'page.html?value=' + ordertype;
    }

Or simply add a submit-button to your form.

And method=post to you form-tag and you will get the value of the selected radiobutton in the querystring without use of the javascript?

Jim H
  • 294
  • 2
  • 9