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

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

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

Post 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
Last edited by s.dot on Thu Aug 03, 2006 3:12 pm, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

That seems like it should work. Try putting document.forms[0].submit() at the end of your determineTarget() function.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

AFAIK: yes
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Thanks peekle, you da man.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply