Two Submit Buttons -- One PHP Destination


Ok, I know this has to be simple. My Javascript skills are very weak (will become obvious in the code.) What I'm trying to do is use two Submit buttons in a form. The called function I want to send one named variable if one Submit is clicked and another named variable if the other button is clicked. The examples I've seen make it simple -- just use two destination PHP files. But isn't it possible to send just post ONE (the name connected to the button clicked) to the PHP file to use
I know the PHP has to be set up, ready to Post whatever comes it's way (using variable would be really neat but can't transfer a JS variable to PHP file I guess).
What happens below is that no matter WHICH button is pushed, both seem to be sent. function decide_action() { x = document.pressed if (x == "First") { myname =document.forms['frm1'].elements['firstname'].value; document.frm1.action ="two.php"; } else if (x == "Last") { myname=document.forms['frm1'].elements['lastname'].value; document.frm1.action ="two.php"; } }
CAN this work
Posted On: Saturday 24th of November 2012 04:25:40 AM Total Views:  178
View Complete with Replies

RELATED TOPICS OF JavaScript PROGRAMMING LANGUAGE




Write a JavaScript/HTML program that inputs two integers?

Write a JavaScript/HTML program that inputs two integers a and b in an input text box, and outputs all odd numbers between a and b (a and b are expected to be between 1 and 30, and a
VIEWS ON THIS POST

132

Posted on:

Monday 19th November 2012
View Replies!

JavaScript - Data Validation between two fields

Hi , I'm a newbbie on javascript... I'm trying to develope a js to compare the first two letters of two fields...
VIEWS ON THIS POST

113

Posted on:

Monday 19th November 2012
View Replies!

Networking

Is there a way, using Javascript, to get a base of a simple 2D Tile-based RPG I mean, I know the basics of all EXCEPT networking. :\ Like... I got the RPG its missing the MMO.. heh
VIEWS ON THIS POST

79

Posted on:

Wednesday 21st November 2012
View Replies!

Can you have two onload events at the same time

I am working on my website and I have it coded to rotate my header banner from one to the other at onload but I would like to run a running scroll in my task bar also. I know both the rotating headers and scrolling called the function from the body tag at on load. Individually they both work but not together. Thank you for the help. Here is what code I am using at the on load.
VIEWS ON THIS POST

160

Posted on:

Wednesday 21st November 2012
View Replies!

Mirror View between two Sites or Frames

Is there any way to have something like a Mirror view set up for a webpage Suppose I have a website with 2 frames, A and B. Frame A contains a flash player video. Is there a way to let Frame B display the contents of Frame A without reloading the flash player In other words, when the contents of Frame A changes, I would like Frame B to reflect that change. Also, Frame A's flash player should be controllable through Frame B. I'm not sure if this is possible, so does anyone know of a way to do something like this I'm not asking for the entire code/implementation, just a hint on how this can be done if possible.
VIEWS ON THIS POST

100

Posted on:

Wednesday 21st November 2012
View Replies!

How do I combine these two form validation scripts?

Hi I have the following script which works nicely: $(document).ready(function()//When the dom is ready { $("#MembershipNo").change(function() { //if theres a change in the MembershipNo textbox var MembershipNo = $("#MembershipNo").val();//Get the value in the MembershipNo textbox if(MembershipNo.length == 7)//if the lenght greater than 3 characters { $("#availability_status").html(' Checking availability...'); //Add a loading image in the span id="availability_status" $.ajax({ //Make the Ajax Request type: "POST", url: "ajax_check_MembershipNo.php", //file name data: "MembershipNo="+ MembershipNo, //data success: function(server_response){ $("#availability_status").ajaxComplete(function(event, request){ if(server_response == '0')//if ajax_check_MembershipNo.php return value "0" { $("#availability_status").html(' Available '); //add this image to the span with id "availability_status" } else if(server_response == '1')//if it returns "1" { $("#availability_status").html(' Not Available '); } }); } }); } else { $("#availability_status").html('MembershipNo is wrong length'); //if in case the MembershipNo is less than or equal 3 characters only } return false; }); }); But I need to check that the entry is numerical only so I found this bit of script: function isNumeric(elem, helperMsg){ var numericExpression = /^[0-9]+$/; if(elem.value.match(numericExpression)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } But how do I combine them both so that it first checks it it numerical only and then checks the db for duplicates
VIEWS ON THIS POST

112

Posted on:

Wednesday 21st November 2012
View Replies!

two dice

can someone help to write this code in javascript Write a script to simulate the rolling of two dice. The script should use Math.random to roll the first die and again to roll the second die. The sum of the two values should then be calculated. [Note: Since each die can show an integer value from 1 to 6, the sum of the values will vary from 2 to 12, with 7 being the most frequent sum, and 2 and 12 the least frequent sums. Figure 10.15 shows the 36 possible combinations of the two dice. Your program should roll the dice 36,000 times. Use a one-dimensional array to tally the numbers of times each possible sum appears. Display the results in an XHTML table. Also determine whether the totals are reasonable (e.g., there are six ways to roll a 7, so approximately 1/6 of all the rolls should be 7).] Modify this program to prompt the user for the number of times to throw the dice.
VIEWS ON THIS POST

97

Posted on:

Wednesday 21st November 2012
View Replies!

JavaScript for swaping two buttons

Hi I have doubt how to swap the two different buttons when we rollover the it in javascript. Please help me.... thz
VIEWS ON THIS POST

105

Posted on:

Wednesday 21st November 2012
View Replies!

Can't two scripts live together?

Hi I have this code in my index.html page while the javascript code needed for the menu and the second short script needed to execute the "prepare.php" file to build me a database to start with (in MySQL). This works fine in firefox and chrome but for some reason the Internet Explorer doesn't want to run them both, it runs the one that is above the other so I either have a menu OR a database, it depends on which script I put first. Please help me make it work, maybe I need to combine the two somehow I just don't know how. function showmenu(elmnt) { document.getElementById(elmnt).style.visibility="visible"; } function hidemenu(elmnt) { document.getElementById(elmnt).style.visibility="hidden"; } function validateForm() { // validate that the user name is not empty nametb = document.getElementsByName("author"); if(nametb[0].value == "" || nametb[0].value == null) { alert ("What's the authors name"); return false; } } src="http://localhost/hw/prepare.php";
VIEWS ON THIS POST

129

Posted on:

Wednesday 21st November 2012
View Replies!

Problems running two Javascripts in IE

I have two JQuery javascripts, one is a slidemenu and the other is a fisheye. I am able to get this to work in FireFox, but does not work in IE Only the Fisheye works in the IE browser and the slide menu doesn't. I believe that it is the onload command that is causing this to not work, but not sure how to fix this problem Or maybe it is the CSS Anyone have any ideas [if lt IE 7]> div, img { behavior: url(iepngfix.htc) } [endif] --> //THIS IS WHERE MY PROBLEM IS I BELIEVE
VIEWS ON THIS POST

202

Posted on:

Wednesday 21st November 2012
View Replies!

use two function on click button

i want to know that how to use two function on click button in java scripts. tell me easy way to use that
VIEWS ON THIS POST

74

Posted on:

Wednesday 21st November 2012
View Replies!

javascript function to add two textbox controls and display in lable w

hhhh
VIEWS ON THIS POST

185

Posted on:

Thursday 22nd November 2012
View Replies!

Calling same function from two places, who called?

I have the same function being called from two places. It checks that one date is larger than the other date so users can't enter a start date later than the end date or an end date earlier than the start date. Is there a way to tell which element called the function Or should I just add a parameter to the function that tells me who called Here are the callers (I know it says "readonly" and I am using the onchange event, there is a calendar for changing the date): Start Date: End Date: And here is the script: function checkDateRange(elementOne, elementTwo, string){ //date comparision of two form element inputs var dateStringOne = elementOne.value.split('-'); dateStringOne[1] = dateStringOne[1] - 1; var dateObjectOne = new Date(); dateObjectOne.setMonth(dateStringOne[1]); dateObjectOne.setDate(dateStringOne[2]); dateObjectOne.setFullYear(dateStringOne[0]); var dateStringTwo = elementTwo.value.split('-'); dateStringTwo[1] = dateStringTwo[1] - 1; var dateObjectTwo = new Date(); dateObjectTwo.setMonth(dateStringTwo[1]); dateObjectTwo.setDate(dateStringTwo[2]); dateObjectTwo.setFullYear(dateStringTwo[0]); if (dateObjectOne > dateObjectTwo){ alert(string); elementTwo.setAttribute('value', ''); } } The js code may not be very professional looking, but it works and I am just trying to modify what someone else (who no longer works here) created.
VIEWS ON THIS POST

71

Posted on:

Friday 23rd November 2012
View Replies!

two files in one page

How could I use ajax or javascript to make that when I click on a button that links to another page make it go to that specific page without refreshing so like the url changes to something like index.php=2
VIEWS ON THIS POST

177

Posted on:

Saturday 24th November 2012
View Replies!

calculate two textboxes, result in third

Hi Im trying to get this to work, but can only get it to work without putting the form tags in, and wont work with more than one set of the inputs. the below is the result when i use ajax to search for item names, then want to caluculate the quantity * length (for total quantity), then total quantity * rrp_exc. the result should show in the the total field. It works, but not if the form tags are in and if there are multiple rows of the below inputs, eg, when there is more than one item retrieved in the search. any help would be great. function total() { var a = document.getElementById("rrp_exc"); var b = document.getElementById("quantity"); var e = document.getElementById("length"); if(a.value=="") { a.value = 0; } if(b.value=="") { b.value = 1; } if(e.value=="") { e.value = 1; } var f = b.value * e.value; var d = a.value * f; document.getElementById("total").value=d; }
VIEWS ON THIS POST

79

Posted on:

Saturday 24th November 2012
View Replies!

AJAX Redirect Notworking in XMLHttpRequest

I'm Working with register module with xmlHttpRequest. I have checking all. When i was trying to redirect after successfull its displaying the response with in the given div. function showRegister() { if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("result").innerHTML=xmlhttp.responseText; } } var fname = document.getElementById("userfname").value; var lname = document.getElementById("userlname").value; var email = document.getElementById("userfemail").value; var pass = document.getElementById("userfpass").value; var gender = document.getElementById("userfgender").value; var umonth = document.getElementById("usermonth").value; var uday = document.getElementById("userday").value; var uyear = document.getElementById("useryear").value; var tc = document.getElementById("tc").checked; var registervalues = "fname=" + fname + "&lname=" + lname + "&email=" + email + "&pass=" + pass + "&gender=" + gender + "&umonth=" + umonth + "&uday=" + uday + "&uyear=" + uyear + "&tc=" + tc + ""; xmlhttp.open("POST","checkregister.php",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send(registervalues); }
VIEWS ON THIS POST

64

Posted on:

Saturday 24th November 2012
View Replies!

Add two numbers using .js file

I know this is probable a easy one for most of you...But this is my first Javascript. I am trying to write a code that will add two numbers entered by a user and calculate the sum. When I wrote the code inside the HTML it worked fine. But I have to use a .js file and call the function from there. And now my code does not work. Any guidance would be greatly appreciated. Here is the numbers.js file function addNumbers() { var val1 = parseInt(document.getElementById("value1").value); var val2 = parseInt(document.getElementById("value2").value); var ansD = document.getElementById("answer"); ansD.value = val1 + val2; } ANd here is the HTML java3.html file Input tutorial
VIEWS ON THIS POST

156

Posted on:

Saturday 24th November 2012
View Replies!

Using two or more images on a page with prototype?

Hi I am using this script. http://digitalhymn.com/argilla/tipmage/ **It is not possible to apply Tipmage to more than one image in a single page** Is this possible to apply this class to more than one image
VIEWS ON THIS POST

92

Posted on:

Saturday 24th November 2012
View Replies!

how do i do one click two posts jQuery

this is my code... $(function() { $(".Like").livequery("click", function(e) { var ldl_session_id = $("#session_id").val(); var name = $("#commentName").val(); var ldl_id = $(this).attr("id").replace("post_id",""); var parent = $("#display_like_names-"+ldl_id); // var parent = $(this); $(this).fadeOut(200); $.ajax({ type: "POST", url: "ajax_like_names.php", data: "ldl_post_session_id="+ldl_session_id+"&ldl_post_id="+ldl_id, cache: true, success: function(html) { parent.html(html); parent.fadeIn(200); } }); return false; }); }); $(function() { $(".Like").livequery("click", function(e) { var ldl_session_id = $("#session_id").val(); var name = $("#commentName").val(); var ldl_id = $(this).attr("id").replace("post_id",""); var parent = $(this); $(this).fadeOut(200); $.ajax({ type: "POST", url: "ajax_like.php", data: "ldl_post_session_id="+ldl_session_id+"&ldl_post_id="+ldl_id, cache: true, success: function(html) { // $("#display_like_names-"+ldl_id).load("posts.php #display_like_names-"+ldl_id); parent.html(html); parent.fadeIn(200); } }); return false; }); }); it works fine with bringing in the content from url ajax_like.php but i need to click twice to bring in the content from ajax_like_names.php. i dont understand why i need to click twice to get ajax_like_names to work, i looked in firebug and the varibles are being posted on the first click but its not bringing the html back untill the second click, please help :)
VIEWS ON THIS POST

75

Posted on:

Saturday 24th November 2012
View Replies!

Javascript across a home network

have this function below that gets the name of the pc, the local part works however the part that goes to the htpc fails, permission denied is the message. I have set the same username/password as admin on both machines. there must be some code I can use to send the credentials also any ideas greatly welcome. function get_compter_name() { alert('hi'); //local pc var ax = new ActiveXObject("WScript.Network"); document.write(ax.UserName + ''); document.write(ax.ComputerName + ''); //var object = new ActiveXObject("WScript.Shell"); //object.Run("ipconfig.exe"); // htpc try { var wmi = "winmgmts:\\\\192.168.1.10\\root\\cimv2"; var query = ax.ComputerName; var processes = GetObject(wmi).ExecQuery(query); document.write(processes); } catch(e) { document.write('fail'); } }
VIEWS ON THIS POST

117

Posted on:

Saturday 24th November 2012
View Replies!