PDA

Click to See Complete Forum and Search --> : Jscript - why does this not want to work in NS


turfbult
Jan 18th, 2001, 12:42 AM
Hello,

I have this jscript function which works perfectly in IE, but not in Netscape. When I click the submit button in NS - nothing happens - no error, no "do you want to debug" - nothing.

Here's the function... it just checks what was selected in a dropdown(lstcountry) and then loads some page accordingly.

My submit button code is just something like
<input type="button" onclick="submitit()"




function submitit() {

// get country
var sCountry = new String(document.frmcountry.lstcountry.value.substring(0,1).toUpperCase());


var sActionPage = new String();

// determine which page to send form to
if (sCountry == "*") {
sActionPage = "city.asp";
} else {
sActionPage = "province.asp";
}

// set form action
document.frmcountry.action = sActionPage;


// submit form
document.frmcountry.submit();

return;
}

</script>

Ianpbaker
Jan 18th, 2001, 05:26 AM
Hi turfbult.

Unfortantlely the way you access the current value of the listbox only works in ie and and not MS. you need to use a slightly more complicated line for it to work in both and is as follows


var sCountry = new String(document.frmcountry.lstcountry.options[document.frmcountry.lstcountry.selectedindex].value.substring(0,1).toUpperCase());




Hope this helps

Ian

turfbult
Jan 18th, 2001, 06:27 AM
Hi Ian,

I get this error -

error 'document.frmcountry.lstcountry.options[...].value' is not an object.

Any ideas?? Does this code not try and retrieve the INDEX of my dropdown instead of the value/text??

T.

Ianpbaker
Jan 18th, 2001, 07:08 AM
what the code does is in two stages

the part inside the [] gets the index of the selected option where the outside part get's the value of the selected option. there shouldn't be anything wrong with that if everything in you code is the same (including case)

try it first without ant of the substring at the end and see it it works

Ian

turfbult
Jan 18th, 2001, 08:13 AM
You're right it DOES work, but...
selectedindex should have a CAPITAL "I" - selectedIndex!!

I never knew that Jscript is so "touchy"!!!!

Thanks for the help Ian,
T

Ianpbaker
Jan 18th, 2001, 08:19 AM
Sorry mate that was my fault. I forgot to put it in myself.

unfortunatley javascript is case sensative. you could be looking at a piece of code for eon's trying to work out why it isn't working and all it is is a capital letter missing

aaggghhh

Jan 19th, 2001, 07:35 AM
javascript:window.resizeto(640,480);
And watch it not work!!!!
Took me ages to realise that it should have been
javascript:window.resizeTo(640,480);

Ianpbaker
Jan 19th, 2001, 07:54 AM
That's one of the reason's why I carry interdev around with me all the time as it lays out the functions like vb does.
People say to me that real developers only use text editor's but I know what most things do and if it makes me more preductive then I don't see the peoblem.

Ian