Page 1 of 1

determining which button is clicked, and switching..[SOLVED]

Posted: Thu Aug 03, 2006 1:58 am
by s.dot
My form action is currently set to target="iframe", so when someone submits.. their form is processed by a page within an iframe.

I want to have two buttons. One button (which i already have) that sends the target to the iframe and the result is displayed there. However, I want to have another button to submit the form to a full page. target="_blank"

How can I use javascript to determine which button was clicked, and then send the form to the appropriate target? I know i should use my own function, but I don't know how to address the target of the form.

something like this?

Code: Select all

<script type="text/javascript">
function determineTarget(buttonclicked){
   if(buttonclicked == 'iframe'){
      document.forms[0].target = 'iframename';     //<--------- Need help there?
   } elseif(buttonclicked == 'fullpage'){
      document.forms[0].target = '_blank';       //<---------- Need help there?
   }
}
</script>

<form action="page.php" method="post" target="HELPMEEEE">
<input id="iframe" type="submit" onClick="determineTarget(this);" value="View In IFrame">
<input id="fullpage" type="submit" onClick="determineTarget(this);" value="View Full Page">
</form>
Yeahhh something like that? But something that would work. :P

Posted: Thu Aug 03, 2006 9:58 am
by pickle
That seems like it should work. Try putting document.forms[0].submit() at the end of your determineTarget() function.

Posted: Thu Aug 03, 2006 2:36 pm
by s.dot
Hmm, i think my problem is throughout the form i'm using onClick="document.forms[0].submit();".. thus submitting the form with javascript, and submitting to the iframe

I think what i'll have to do is instead of using that, use onClick="determineTarget('iframeName');".

Is document.forms[0].target the correct way to address the target of the form?

Posted: Thu Aug 03, 2006 2:41 pm
by pickle
AFAIK: yes

Posted: Thu Aug 03, 2006 3:11 pm
by s.dot
Thanks peekle, you da man.