PDA

View Full Version : simple javascript function - IE good, FF bad...


glenn.php
05-27-2008, 12:10 PM
wonder why this would not work in FF (only opens in _self, regardless...)


function OnButton2() {
document.form.action = "process/processInsert.php";
if (form.coupon.value == "HJ5627") {
document.form.target = "_self"; // Open in a new window
} else {
document.form.target = "_top"; // Open in a new window
// document.form.submit(); // Submit the page
}
}


while this does (DOES open in _top):


function OnButton1() {
document.form.action = "prevpost.php";
document.form.target = "_top"; // Open in a new window
// document.form.submit(); // Submit the page
}


and both work in IE7...

(i'm not a javascripter)

thanks for anyone's help.

GN

glenn.php
05-27-2008, 12:13 PM
aha - found it...

FF didn't like this:
if (form.coupon.value == "HJ5627")


it likes this:
if (document.form.coupon.value == "HJ5627")

THANKS YA'LL!!!

cmetz1977
05-28-2008, 02:18 PM
a few shortcuts for you:

if you are going to access document.form a lot, create a variable

var form = document.form

Then it is easy to access: form.firstname.value, form.submit(), form.target = ...

if you are using 'onsubmit' in your form credentials, use 'this' to generate that shortcut...

<form name='form' action='formaction.html' method='post' onsubmit='return validate( this )'>

function validate( obj )
{
if( obj.firstname.value == '' )
{
obj.firstname.focus( )
return flase
}
else return true
}

glenn.php
05-28-2008, 02:22 PM
thanks very much!

cmetz1977
05-28-2008, 02:25 PM
no problem, less typing:

let the computer do all the work.