Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why Netscape won't work with this code?

Status
Not open for further replies.

moepower

Programmer
Oct 5, 2000
93
US
I have a form with two buttons (accept, decline). When "accept" is choosen, it goes to billing. When "decline" is choosen, it displays a message then goes back to the main page.
The code works fine in IE, but in Netscape both "accept" and "decline" buttons take me to the billing page. Why is this?

function validate(form) {
if (working == false) {
working = true;
document.forms[1].submit();
return false;
} else {
return false;
}
}

function getConfirmation() {
message = "decline message here.";
if (confirm(message)) {
document.forms[1].decline.value="I Decline";
document.forms[1].submit();
return false;
} else {
return false;
}
}

<FORM NAME=&quot;Subscriber&quot; ACTION=&quot;<%= ... %>&quot; METHOD=&quot;POST&quot;>

<a href=&quot;#&quot; onClick=&quot;return validate(document.forms[1],this);&quot;><img NAME=&quot;accept&quot; ALT=&quot;Accept&quot; SRC=&quot;/accept.gif&quot; border=0></a>

<a href=&quot;#&quot; onClick=&quot;return getConfirmation();&quot;>
<img NAME=&quot;decline&quot; ALT=&quot;Decline&quot; SRC=&quot;/decline.gif&quot; border=0></a>

Thanks,
 
If you hit decline, then &quot;OK&quot; in the confirm box with either NS 4.7, 6.0 or IE 5.5 on my box it submits the form and takes you to the next page (the action of the form). (I had to make the form the 2nd on on the page and add a hidden field named &quot;decline&quot; to get it to work w/ your code...)

For the getConfirmation (decline) function, why are you submitting the form anyway? That's what's sending them there, it doesn't look like it's the browser. If you hit &quot;cancel&quot; it stays there... is that the desired behavior? If not, you need to change it from a form submission to a redirect when they click the decline button AND &quot;ok&quot;, form submission will take them to the same place.

If you need a form submission in both cases (as in you are passing the &quot;decline&quot; variabe somewhere else,) you would need to create a seperate form w/ a different action. Then have the function submit that form instead.

Hope that helps some... :)

-Scott
 
You are correct that both the &quot;accept&quot; and &quot;decline&quot; buttons have to do a submit because the &quot;decline&quot; value has to be passed to a .jsp and the appropriate URL returned.

I put the submit in both functions then return &quot;false&quot; so the default action of the href=&quot;#&quot; will not be done.

If this is incorrect, could you give me an example what I should do with my code.

Thanks,
 
moepower, I just checked you're code in NS and IE and they work fine in both browsers...when you hit the DECLINE button a pop-up message appears saying &quot;DECLINE MESSAGE&quot;... I have not failed; I merely found 100,000 different ways of not succeding...
 
Yeah, np, just create a new form:
Code:
<form name=&quot;declineform&quot; action=&quot;the_jsp_i_need_to_go_to&quot;>
<input type=&quot;hidden&quot; name=&quot;decline&quot;>
</form>

Then in your getConfirmation() function, submit that form instead.

Code:
function getConfirmation() {
  message = &quot;decline message here.&quot;;
  if (confirm(message)) {
    document.forms[2].decline.value=&quot;I Decline&quot;;
    document.forms[2].submit();
    return true;
  } else {
    return false;
  }
}

That will work, assuming it is the form immediately following the first one...

-Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top