Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-08-2006, 12:29 PM   PM User | #1
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
passing button name and value via submit()?

Hi all,

I have written a little bit of PHP which turns this:

Code:
<form method="[whatever]" action="[wherever]" name="[form name]">
  <input name="mytextbox" type="text" />
  <confirm name="callback" value="do this" message="Do you really want to do this?" />
  <confirm name="callback" value="do that" message="Do you really want to do that?" />
</form>
Into this:

Code:
<form method="[whatever]" action="[wherever]" name="[form name]">
  <input name="mytextbox" type="text" />
  <input type="button" onclick=confirmSubmit("callback", "do this", "[form name]", "Do you really want to do this?" />
  <input type="button" onclick=confirmSubmit("callback", "do that", "[form name]", "Do you really want to do that?" />
</form>
which uses the following javascript:

Code:
<script language="javascript">
<!--
  function confirmSubmit(bkey, bvalue, fname, confmsg)
  {
    var response;

    /*** Need something here to pass bkey and bvalue as a key/value
     *** pair when the form is submitted.
     ***/

    if (formname != "")  //The PHP automatically inserts the form name into the function call, or "" if it is not specified.
      {
        response = confirm(confmessage);

        if (response == true)
          document.forms[formname].submit();
      }
    else alert("Programming Error - The form needs a name!");
  }
// -->
</script>
This makes it nice and quick for me to stick submit-like buttons into forms that require user confirmation for the form to be submitted.

*BUT* how can I pass the name and value of what I've called a "confirm" element with the other form data (see the comment in the javascript)?

What I'd like to see in the callback data ($_REQUEST) from the given example would be:

Code:
"mytextbox" => [user inputted value],
"callback" => [either "do this" or "do that" depending on the source of the confirmation event]
Any ideas?

Thanks,
Mike.
__________________
Die Welt ist ein Irrenhaus und hier ist die Zentrale!
mlse is offline   Reply With Quote
Old 12-08-2006, 12:41 PM   PM User | #2
mlse
Regular Coder

 
mlse's Avatar
 
Join Date: Mar 2005
Posts: 624
Thanks: 20
Thanked 19 Times in 18 Posts
mlse is on a distinguished road
Hey, I fixed my own post! Lol!

Will post solution after my lunch incase anyone else is remotely interested!
__________________
Die Welt ist ein Irrenhaus und hier ist die Zentrale!
mlse is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:53 AM.


Advertisement
Log in to turn off these ads.