473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

handling forms

How can I pass user's browser, OS and resolution information to the
form element?

I need to make radiobuttons to be checked by default according to the
user's information.

For example,
if visitor's browser is IE I would like the radiobutton with
value="Internet Explorer" to be checked by default.

Thanks.

Here is the part of the form:

<html>
<head>
<script language="JavaScript">

var browserName = navigator.appName
var browserVersion = navigator.appVersion
var OS = navigator.userAgent
var screenWidth = screen.width
var screenHeight = screen.height
document.write("Browser: <b>"+ browserName + " ??" +
browserVersion + "</b><br>")
document.write("OS: <b>" + OS + "</b><br>")
document.write("Screen resolution: <b>" + screenWidth + "
</b>x<b> " + screenHeight + "</b><br>")

</script>

</head>
<form name="form1" method="post" action="">
<input type="radio" name="browser" value="Internet
Explorer">Internet Explorer<br>

<input type="radio" name="browser" value="Netscape">Netscape<br>

<input type="radio" name="browser" value="Other">Other<br>

<hr color="red" width="200" align="left">

<input type="radio" name="OS" value="Win 95">Windows 95<br>

<input type="radio" name="OS" value="Win XP">Windows XP<br>

<input type="radio" name="OS" value="Win 2000">Windows 2000<br>
</form>

</html>
Jul 20 '05 #1
2 2022
fo******@yahoo.com (Hamster) writes:
How can I pass user's browser, OS and resolution information to the
form element?
That's the easy part. The hard part is to find the OS and browser
(resolution is pretty standardized in screen.width, screen.height
and screen.pixelDepth).

To set a radiobutton in your form, use the following function:
---
function setRadio(form,radioGroupName,value) {
var rg = form.elements[radioGroupName];
if (!rg.length) { // not a group, so only one element
rg.checked = true;
return;
}
for (var i=0;i<rg.length;i++) {
if (rg[i].value == value) {
rg[i].checked = true;
return;
}
}
}
---
Then call it as, e.g.,
---
setRadio(document.forms["form1"],"browser","Netscape");
---
I need to make radiobuttons to be checked by default according to the
user's information.
Use the above function after the page has loaded.
For example,
if visitor's browser is IE I would like the radiobutton with
value="Internet Explorer" to be checked by default.
if (browseIsIE) {
setRadio(document.forms["form1"],"browser","Internet Explorer");
}
<script language="JavaScript">
In HTML 4, the type attribute is required, and it is sufficient in
all versions.
<script type="text/javascript">
var browserName = navigator.appName
var browserVersion = navigator.appVersion
var OS = navigator.userAgent
You can't trust these values if the browser tries to look like another
browser. Since the user has a chance to correct the values, it only means
that the initial setting is the one the user has asked his browser to
show, so it's an acceptable mistake.

Add:
---
function init() {
var detectedOS;
var detectedBrowser;
// determine browser and OS
setRadio(document.forms['form1'],"browser",detectedBrowser);
setRadio(document.forms['form1'],"OS",detectedOS);
}
</script>

</head>
You are missing the <body> tag. Always validate your code before
asking for help!

<body onload="init()">
<input type="radio" name="browser" value="Internet
Explorer">Internet Explorer<br>

<input type="radio" name="browser" value="Netscape">Netscape<br>
The difference between Netscape 4 and Netscape 7 is bigger than
the difference between Netscape 7 and IE 6.

What if I use Mozilla, which shows pages exactly the same as Netscape
7? Should I select Netscape?
<input type="radio" name="browser" value="Other">Other<br>
Good that this choice is included. We are not living in the era
of "both browsers" any more.
<hr color="red" width="200" align="left">

<input type="radio" name="OS" value="Win 95">Windows 95<br>

<input type="radio" name="OS" value="Win XP">Windows XP<br>

<input type="radio" name="OS" value="Win 2000">Windows 2000<br>


What about "Other" here (non Windows and Win98, WinME, and WinNT5)?

What is this for, anyway?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
Thank you very much. Your advices are very helpful.

<What if I use Mozilla, which shows pages exactly the same <as Netscape
<7? Should I select Netscape?

I gave you just a part of that form, the real form has more options.
<What about "Other" here (non Windows and Win98, WinME, <and WinNT5)?

Actually, there is "other" in this case.


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: WindAndWaves | last post by:
I am writing error handling procedures at the moment. Here are some questions: 1. Can you write a procedure that picks up any error and deals with it no matter where it happens in the database?...
7
by: Ori | last post by:
Hi, I would like to create some mechanism to handle all the exceptions which will happen in my application. I have one form which is the base form while all the other forms inherit from it. ...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
5
by: OHM | last post by:
Hi everyone, I have a problem with error handling and wondered if anyone has managed to implement a global exception handling model. Is it possible to ensure that you see all exceptions before...
5
by: Jason MacKenzie | last post by:
I have a production critical windows forms application. I have try catch blocks everywhere to handle every eventuality. However occasionally, every couple of months, the application crashes. Its...
8
by: jcrouse | last post by:
I am using the following code to trap errors in a sub routine: Try Executable code Catch ex As Exception Dim strInputE As String = Application.StartupPath & "\Error.txt" Dim srE As...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
44
by: Kulgan | last post by:
Hi I am struggling to find definitive information on how IE 5.5, 6 and 7 handle character input (I am happy with the display of text). I have two main questions: 1. Does IE automaticall...
0
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.