Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #1856

simple javascript question: window.location.href

From Roger Darlington <rogerarm@freeuk.com>
Newsgroups comp.sys.acorn.programmer
Subject simple javascript question: window.location.href
Date 2012-06-30 13:45 +0100
Organization home
Message-ID <0a16f1a752.rogerarm@rogerarm.freeuk.com> (permalink)

Show all headers | View raw


In the Javascript below, which was not written by myself, the url that 
I want to invoke when someone presses a button is set in
windows.location.href
whatever that is

You will see that I have attempted to call that href using

<a href="javascript:window.location.href">PRESS THIS INSTEAD</a>

Which doesn't seem to work

How do I do this please?
[Yes I have googled it, but that seems to confuse me still further :-(  
]

                ----------------------------------------------
<!-- Rogers Javascript - start -->
<script language="javascript" type="text/javascript">


// function will loop through all input tags and create
// url string from checked checkboxes
function checkbox_test() {
    var counter = 0, // counter for checked checkboxes
        i = 0,       // loop variable
        url = '',    // final url string
        // get a collection of objects with the specified 'input' TAGNAME
        input_obj = document.getElementsByTagName('input');
    // loop through all collected objects
    for (i = 0; i < input_obj.length; i++) {
        // if input object is checkbox and checkbox is checked then ...
        if (input_obj[i].type === 'checkbox' && input_obj[i].checked === true) {
            // ... increase counter and concatenate checkbox value to the url st 
ring
            counter++;
            url = url + '%20' + input_obj[i].value;
        }
    }

   // display url string or message if there is no checked checkboxes
     if (counter > 0) {
         // remove first "%20" from the generated url string
         url = url.substr(3);
         // display final url string
         //alert(url);
         // do search
         window.location.href =
'http://search.freefind.com/find.html?si=39652138&pid=r&n=0&_charset_=utf-8&bcd= 
%C3%B7&query='
+ url;
     }
     else {
         alert('There are no checked checkboxes');
     }

}

</script>
<!-- Rogers Javascript - end -->

<a href="javascript:window.location.href">PRESS THIS INSTEAD</a>

-- 

Cheers
Roger
All who wander are not lost

Back to comp.sys.acorn.programmer | Previous | NextNext in thread | Find similar | Unroll thread


Thread

simple javascript question: window.location.href Roger Darlington <rogerarm@freeuk.com> - 2012-06-30 13:45 +0100
  Re: simple javascript question: window.location.href Vince M Hudd <vinceh@softrock.co.uk> - 2012-06-30 17:16 +0100
    Re: simple javascript question: window.location.href Roger Darlington <rogerarm@freeuk.com> - 2012-06-30 22:40 +0100
      Re: simple javascript question: window.location.href Alan Adams <alan@adamshome.org.uk> - 2012-07-01 22:42 +0100

csiph-web