Forum Moderators: phranque

Message Too Old, No Replies

Will this work in all (or most) browsers?

         

kslnor

5:38 pm on Feb 26, 2006 (gmt 0)

10+ Year Member



Hi,
I am attempting to add a little radio button "form" to one of my pages. Well, I use the word form due to lack of a better description. Basically, I would like the user to click one of the radio buttons, select the GO (submit) buton and be taken to the appropriate page for their selection. Following is the code...will this work in all browsers? More importantly, will this code even do what I want? Thanks from a "still learning, but getting there" webmaster.

<html>
<body>

<html>
<head>
<script language="JavaScript"><!--
function go(what) {
for (var i=0;i<3;i++) {
if (what.page[i].checked) {
document.forms[what.page[i].value].submit();
}
}
}
//--></script>
</head>

<body>

<form action="page1.htm" target="targetframename" name="page1"><input type="hidden" value="page1"></form>
<form action="page2.htm" target="targetframename" name="page2"><input type="hidden" value="page2"></form>
<form action="page2.htm" target="targetframename" name="page3"><input type="hidden" value="page3"></form>

<form>
<input type="radio" name="page" value="page1">Ann Arbor, Michigan<br>
<input type="radio" name="page" value="page2">Dexter, Michigan<br>
<input type="radio" name="page" value="page3">Jackson, Michigan<br>
<p>
<input type="button" onClick="go(this.form)" value="GO">
</form>

</body>
</html>

httpwebwitch

4:51 am on Feb 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you must, try this:

<script>
function gotoit(f){
for (var i=0; i < f.d.length; i++){
if (f.d[i].checked) {
location.href = f.d[i].value;
}
}
}
</script>

<form name="gotoform">
<input type="radio" name="d" value="pageone.htm" /> page one
<input type="radio" name="d" value="pagetwo.htm" /> page two
<input type="radio" name="d" value="pagethree.htm" / > page three
<input type="button" value="GO" onClick="gotoit(this.form)">
</form>

Is there some reason why this is better than using hyperlinks?

encyclo

10:56 am on Feb 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The markup might well work in most normal browsers (with Javascript enabled), but it won't work for search engine spiders who will not be able to follow the links, nor for users without Javascript.

Standard links are almost always better, and if you choose to go with the above arrangement you should at least duplicate the links with standard links elsewhere on the page.

kslnor

7:05 pm on Feb 28, 2006 (gmt 0)

10+ Year Member



Thank you for your replys. I considered using regular hyperlinks, but I thought the radio buttons looked a bit more professional (lack of better words) as the idea I have is to create a (very simple) database where the clicked-upon button will take the visitor to the appropriate page. My thinking is the clickable buttons will visually give a more appealing impression for the visitor. Do you have any other suggestions? The database is to showcase the homes my employer builds, distinguishable by location.