473,385 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

-> How to read a form variable before posting? <-

Hi,
is there a way to read the content of a form variable before
a POST?

I have a form with a "duplicate" button which opens a new form
with most of the fields filled with the values of the calling one.
To do so, I pass the id of the form to be duplicated.
Example:
- I have a form with "Number = 1234567" in a "numform" edit field.
- Duplicate has a href=/duplicateform.php?id=1234567
- then the "duplicateform.php" reads id with a GET['id']

This is easy as I come from a displayed form that retrieves its
values via a SQL statement and with a specific "number" reference.

Now, once I am in this new form, I have a save button to save all
values, including the new "Number" the user would type in, say
"22222222". The save process works correctly via AJAX and saves the
record using a POST action.
But then, I still have my "duplicate" button which should now
point to href=/duplicateform.php?id=22222222
How can I get this 22222222 value from within the form itself?
I have to get it from the "numform" field, but how can I do this?

it would be something like
href=/duplicateform.php?id=<?=[value_of_field_number]?>

with value_of_field_number being the actual value of that edit field.

Any help would be appreciated.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #1
6 1753
As a complement to my question...

I have a hidden form field called "recid" with id="recid".

By default it's set to "-1" to let me know the form is new
and has not been stored in the database.

I was thinking about adding a javascript event to the field's
onBlur() event like:
getElementById("recid").value = getElementById("number").value

to store the value currently in my field.

Then I could use a reference like

<A href="/formduplicate.php?id=<?=$_GET['recid']?>">...</a>

But I'm afraid that this would not work as the recid variable was not
part of a POST event or passed as an URL argument.

Is this correct?
Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #2
How can I get this 22222222 value from within the form itself?
I have to get it from the "numform" field, but how can I do this?
Hi, check out mysql_insert_id()

--
Arjen
http://www.hondenpage.com - mijn site over honden
May 14 '07 #3
Actually, the following code sample works ok to built
the href tag dynamically...

<script language="javascript" type="text/javascript">
function toto() {
var num = document.getElementById("num") ;
var ref=document.getElementById("theref") ;
ref.href="mypage.php?id="+num.value ;
}
</script>

<form method="post">
<INPUT name="num" type="text" id="num" onBlur="toto();">
<A href="" id="theref">go</a>
</form>

When I click on "go" the link is correct and point to mypage
with the id= to the value I have in the edit field.

This allows me to know where to point to before POSTING. That's
what I need.
Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #4
On May 14, 2:56 pm, Steve JORDI <steveK_I_L_LSPAMjo...@hotmail.com>
wrote:
Actually, the following code sample works ok to built
the href tag dynamically...

<script language="javascript" type="text/javascript">
function toto() {
var num = document.getElementById("num") ;
var ref=document.getElementById("theref") ;
ref.href="mypage.php?id="+num.value ;
}
</script>

<form method="post">
<INPUT name="num" type="text" id="num" onBlur="toto();">
<A href="" id="theref">go</a>
</form>

When I click on "go" the link is correct and point to mypage
with the id= to the value I have in the edit field.

This allows me to know where to point to before POSTING. That's
what I need.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: stevejordiK_I_L_LS...@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
of course you could just post to mypage, and use
$_GET['id'] = $_POST['numform']; //with filtering of course!
if you REALLY need to populate the GET array.

May 14 '07 #5
I actually need to know the id of my record BEFORE
posting, so I can dynamically create the <A href>
link with the correct value passed to the mypage file.

So my javascript function does exactly what I need.

Thanks anyway.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: st*******************@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
May 14 '07 #6
On May 14, 3:10 pm, Steve JORDI <steveK_I_L_LSPAMjo...@hotmail.com>
wrote:
I actually need to know the id of my record BEFORE
posting, so I can dynamically create the <A href>
link with the correct value passed to the mypage file.

So my javascript function does exactly what I need.

Thanks anyway.

Sincerely,
Steve JORDI

(Remove the K_I_L_LSPAM from my email address)
------------------------------------------------
1197 Prangins Email: stevejordiK_I_L_LS...@hotmail.com
Switzerland WWW: www.sjordi.com
------------------------------------------------
Volcanoes at www.sjordi.com/volcanoes
MovieDB at www.sjmoviedb.com
------------------------------------------------
if you say so

May 14 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex | last post by:
This may sound like a simple question but I really dont' know how to do this. I know you can call a Form Variable in a VBscript using Request.Form("FieldName") and make equal a local variable...
10
by: yawnmoth | last post by:
i've written some javascript code that i believe should set a form variable to a certain value, depending on what the user clicks on. unfortunately, it isn't working. here's the url: ...
2
by: bebelino | last post by:
Hello, this should be an easy one, but I've had always troubles with it. How to pass trough a querydef-variable, form-variable and so on from a function to the caller-routine? Is there a simply...
13
by: Ian.Suttle | last post by:
I am have been researching this issue to no end, so any help would be very much appreciated. I have a page with form tags. Inside of the form tags is a panel that contains a user control. The...
7
by: Alan | last post by:
I have a main form frmMain and second form frmMember, I declare a variable at the top of the frmMember as Dim memberStr as String In the main form, Dim MemberForm as frmMember
5
by: yinglcs | last post by:
Hi, I have a method like this: const A* getMaxArea(const vector<A*>& aList); And in my caller, i have this: A* const a = NULL;
5
by: Diego Pino | last post by:
Hello, I am experience some problems reading a form variable from a Javascript function. The point with this particular variable is that its name has the following syntax: <input...
8
by: tnspc | last post by:
I'm trying to access a Request.Form variable and plug it into an SQL statement, so that the statement will select just the particular data I need. Here's the offending snippet of code: sql =...
5
by: RacerX2000 | last post by:
I have an MS access Database (2000) and Have created a form that sets a variable to a value I would like (Based on other selections in the form) to pass to my query criteria and I get the following...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.