Forum Moderators: open

Message Too Old, No Replies

Please check my JS

I am new at this and not sure what I am doing.

         

ron_ron

4:52 pm on Jul 20, 2006 (gmt 0)

10+ Year Member



One the top page of my site, I have some JS (in both head and body) which displays insurance rates in a text field depending on which items are selected from two separate select menus.

Please go to "healthone.jp" and play with the select menus in the center of the page. Then please have a look at how I have it coded.

My undersatnding of JS is very low-level.

chenggn

5:02 pm on Jul 20, 2006 (gmt 0)

10+ Year Member



Where is your site? :)
--
AJAX AutoComplete [capxous.com]

daveVk

2:40 am on Jul 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We do not need to define trapSpecial twice, remove the one in the body.

Also may wish to reduce verbosity a bit

var x=tmp[tmp.selectedIndex].value;
var y=tmp2[tmp2.selectedIndex].value;
var z=0;
if (( x=="1")&&(y=="10")) { z="44,800"; }
...
document.Premium.premium.value=z;

directrix

1:17 pm on Jul 21, 2006 (gmt 0)

10+ Year Member



You may find JSLint useful. Be sure to read the documentation, or the error messages may seem rather cryptic.

ron_ron

4:54 pm on Jul 22, 2006 (gmt 0)

10+ Year Member



Dave, thanks for the advise but I do not undrstand what you mean by not defining trapSpecial twice. It does not seem to be defined in the body.

daveVk

4:02 am on Jul 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When I do view source, this is cutdown version of what I see.

<html>
<head>
<title>Untitled</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="style.css" rel="stylesheet" type="text/css">

<script language="javascript" type="text/JavaScript">
<!--
function trapSpecial() {
var tmp = document.AgeRange.AgeRange;
var tmp2 = document.Deductible.Deductible;
.... cut ....
}
//-->
</script>
</head>
<body style="background-image:url(images/bg.gif); background-repeat:repeat-x" >

<table cellpadding="0" cellspacing="0" border="0" align="center" >
<tr>
.... cut ......
<img src="images/quote.gif" style="margin-bottom:11px" alt="" border="0"><br>
<script language="javascript" type="text/JavaScript">
<!--
function trapSpecial() {
var tmp = document.AgeRange.AgeRange;
var tmp2 = document.Deductible.Deductible;
if ( tmp[tmp.selectedIndex].value == "1" )
..... cut ........
}
//-->
</script>

<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="20%">
Select Age Range:</td><td>
<form name="AgeRange" method="post">
<select name="AgeRange" onChange="trapSpecial();">
<option value="0">Select</option>
.....cut .......

p.s.
Recommend reviewing <title> tag contents. Very important for google and other seach engines.

ron_ron

8:46 am on Jul 23, 2006 (gmt 0)

10+ Year Member



Dave,

Thanks for this, it was very helpful. I did what you suggested. May I ask just a couple more questions?

Can you tell me if the code as it is now (per your instructions) is fairly compatible with various browsers? Something strange happen when I look at the select boxes in IE 5.5 for Mac. I see the word select, but in the lower select box, I do not see any text below the word select. If you select something, then it shows.

Also, in my body code, I have:

<form name="AgeRange" method="post">

Is method="post" correct? Should I be using something else?