473,785 Members | 2,321 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multi-step script

First off, I am mostly familier with PHP but am trying to make a
multi-step javascript program. For an example, I would like to run
different sections of the script depending on how many times the user
presses the submit button:

<form method="post" name="step1" action="test.ht ml">

<script language="JavaS cript">

var position
if (! position)
{
alert("Position 0")
document.write( "<input type = \"hidden\" name = \"position\" value =
\"1\">")
document.close( )
}
if (position=1)
{
alert("Position 1")
document.write( "<input type = \"hidden\" name = \"position\" value =
\"2\">")
}

</script>

<div align=right><br ><input TYPE = "submit" Value = " Next
"></div></form>

I keep running into problems...for example, javascript doesn't have an
isset command that I know of, so I can't just use hidden elements to
determine what part of the script to run. I tried using form method get
to use variables in the location to determine which parts run, but I am
not sure how to pull the variables out of the location bar using
javascript. I think I am trying to make this more complex than it
is...what is the best way to go about this?

Jul 20 '05 #1
6 3779
"Andrew V. Romero" <rr*******@icqm ail.com> wrote in message
news:3F******** ******@icqmail. com...
First off, I am mostly familier with PHP but am
trying to make a multi-step javascript program.
You probably know exactly what you mean by "multi-step" but if you don't
explain no one else will. (in one sense of another all programs are
"mult-step").
For an example, I would like to run different sections
of the script depending on how many times the user
presses the submit button: <snip>

Given that pressing a submit button will submit a form and (if
JavaScript is enabled/available on the client) activate the onsubmit so
each onsubmit handler could assign a reference to a separate (the next)
function to the forms onsubit handler for execution with the next
submit ckick. Though the user wont get a chance to click the submit
button that many times before the browser starts to load the response to
the form being submitted by the first click (assuming submission was not
cancelled).
I keep running into problems...for example, javascript doesn't
have an isset command that I know of,
I can only guess as to what isset does but:-

if(typeof globalVarName != 'undefined')

is probably the sort of thing you are after.
so I can't just use hidden elements to
determine what part of the script to run.
The desire to use a hidden for element implies wanting to persist
information across multiple pages, otherwise why not use a global
JavaScript variable.
I tried using form method get to use variables
in the location to determine which parts run, but I am
not sure how to pull the variables out of the location bar
using javascript.
location.href
-or-
location.search
I think I am trying to make this more complex than it
is...what is the best way to go about this?


Start by creating a clear and concise explanation of what you are really
trying to achieve.

Richard.
Jul 20 '05 #2
---
Start by creating a clear and concise explanation of what you are really
trying to achieve.
---

Okay, let me try again (I was afraid that I would scare people off if I
went into details). I am trying to recreate a web page that I made
using PHP and javascript (see http://www.u.arizona.edu/~avr/umc/tpn/).
Most of the work for this page is done with javascript except for a few
details. Currently, index.html gathers the information entered on the
first form and pass the information onto another TPN.phtml which
displays the next form in slightly different forms with different
options depending on what the user selected on the first form. So what
I would like to do is have one html page that has a long javascript take
care of everything instead of having 2 seperate html pages. So in order
for this to work, when my new page newPage.html loads, it needs to
display the first form (currently index.html). When the user fills in
this first form and hits submit, I want the same page (newPage.html) to
reload and display one of several forms depending on the choices the
user makes in the first form. The area I am getting stuck in is how to
have the same page display this first form, then have the user hit
submit, and have another form pop up which uses information from the
first form. So far when the user presses the submit button, I keep
getting that first form to come up and am not sure how to not have it
come up.

Now that we have gone complex...to make things simple again. I would
really like to see one html page with one javascript that displays a
text field and a submit button. When the user hits submit, if there is
something in the text box I want an alert box to display #1
$textFieldEntry and for the form to redisplayed with an html line that
says submit hit once at the top. Now if the user types in something
else and hits submit, I want the alert box to pop up and say #2
$textFieldEntry and display an html line that says submit hit twice at
the top of the page. So each time submit is hit, I want it to call a
different funtion, how can I have one html page that calls a different
funtion depending on how many times the submit button is hit? I would
really love to see an html page that does what I described above,
because this would get me past this block that I have.

Thanks for all your help, sorry if I wasn't clear before.
-Andrew V. Romero

Richard Cornford wrote:
"Andrew V. Romero" <rr*******@icqm ail.com> wrote in message
news:3F******** ******@icqmail. com...
First off, I am mostly familier with PHP but am
trying to make a multi-step javascript program.

You probably know exactly what you mean by "multi-step" but if you don't
explain no one else will. (in one sense of another all programs are
"mult-step").

For an example, I would like to run different sections
of the script depending on how many times the user
presses the submit button:


<snip>

Given that pressing a submit button will submit a form and (if
JavaScript is enabled/available on the client) activate the onsubmit so
each onsubmit handler could assign a reference to a separate (the next)
function to the forms onsubit handler for execution with the next
submit ckick. Though the user wont get a chance to click the submit
button that many times before the browser starts to load the response to
the form being submitted by the first click (assuming submission was not
cancelled).

I keep running into problems...for example, javascript doesn't
have an isset command that I know of,

I can only guess as to what isset does but:-

if(typeof globalVarName != 'undefined')

is probably the sort of thing you are after.

so I can't just use hidden elements to
determine what part of the script to run.

The desire to use a hidden for element implies wanting to persist
information across multiple pages, otherwise why not use a global
JavaScript variable.

I tried using form method get to use variables
in the location to determine which parts run, but I am
not sure how to pull the variables out of the location bar
using javascript.

location.href
-or-
location.search

I think I am trying to make this more complex than it
is...what is the best way to go about this?

Start by creating a clear and concise explanation of what you are really
trying to achieve.

Richard.


Jul 20 '05 #3
AFAIK JavaScript runs in the context of a HTML page that is displayed in the
browser. As soon as a submit takes place the browser will reload the frame,
thereby completely unloading (and in this case, reloading/initializing) the
JS. The only way to get the JS in the logical state you want it to be after
the submit would be to have the server generate enough history information
into the page that can be interpreted by the JS.

Regards,

Silvio Bierman
Jul 20 '05 #4
"Andrew V. Romero" <rr*******@icqm ail.com> wrote in message
news:3F******** ******@icqmail. com...
<snip>
... . The area I am getting stuck in is how to have the
same page display this first form, then have the user hit
submit, and have another form pop up which uses information
from the first form. ...
This all seems like the sort of thing that server scripting was
introduced to achieve and a server-side implementation would inevitably
be considerably more reliable that using client side scripts to modify
the form. But still your explanation is too vague to see how your stated
desire to use different functions at different stages fits into the
process.
Now that we have gone complex...to make things simple again. I
would really like to see one html page with one javascript that
displays a text field and a submit button. When the user hits
submit, if there is something in the text box I want an alert box
to display #1 $textFieldEntry and for the form to redisplayed with
an html line that says submit hit once at the top. Now if the
user types in something else and hits submit, I want the alert
box to pop up and say #2 $textFieldEntry and display an html line
that says submit hit twice at the top of the page.
Now that is more like a specification, though the requirement for a
round trip to the server seems unnecessary and given that requirement,
again, a server side PHP implementation would be more reliable.

However, there is no need for any changing of functions in this
specification. This is a page that does what you have asked for:-

<html>
<head><title> </title>
<script type="text/javascript">
var queryStrings = (function(out){
if(typeof location != 'undefined'){
var temp = location.search ||location.href ||'';
var ofSet;
if((ofSet = temp.indexOf('? ')) > -1){
temp = temp.substring( (ofSet+1), temp.length);
var workAr = temp.split('&') ;
for(var nvp,c = workAr.length;c--;){
nvp = workAr[c].split('=');
if(nvp.length > 1){
out[nvp[0]] = nvp[1];
}
}
}
}
return out;
}({})); //inline function expression call passed an object
// literal - {} - as its parameter (out).

function getElById(ID){
if(document.get elementById){
return document.getele mentById(ID);
}else if(document.all ){
return document.all[ID];
}
return null;
}

function validate(){
var frm = document.forms['aForm'];
var subCountEl = frm.elements['subCount'];
subCountEl.valu e = (+subCountEl.va lue) + 1;
alert('#'+subCo untEl.value+' '+frm.elements['sText'].value);
return true;
}

function setUp(){
document.forms['aForm'].elements['subCount'].value =
(+queryStrings["subCount"])||0;
document.forms['aForm'].elements['sText'].value =
(queryStrings["sText"])||'';
}
</script>
</head>
<body onload="setUp() ">
<p id="dnyText"><s cript type="text/javascript">
if(queryStrings["subCount"]){
document.write( 'submit hit '+queryStrings["subCount"]+' times');
}else{
document.write( 'First Load');
}
</script></p>
<form name="aForm" action="" method="get"
onsubmit="retur n validate();">
<input type="text" name="sText" value=""><br>
<input type="submit" name="sub">
<input type="hidden" name="subCount" value="">
</form>
</body>
</html>
So each time submit is hit, I want it to call a different
funtion, how can I have one html page that calls a different
funtion depending on how many times the submit button is hit?
Your specification does not require that. It would however be possible
to use the value that my page recovers from the query string that
corresponds with hidden filed that is being used to track the number of
submits in a - select - statement that called a different function based
on that number (except that as recovered from the query string and as a
hidden input value it is really a string).
I would really love to see an html page that does what I
described above, because this would get me past this block
that I have.


Richard.
Jul 20 '05 #5
As you mentioned, I would be ideal to do this sort of project using PHP,
unfortunately, my place of emoployment does not have PHP installed and
is not interested in installing it. So that sort of leaves me with
javascript and other client side tricks to accomplish my goals. So far
it has been interesting trying to make javascript do some of things that
PHP is better at.

Thanks for the sample script, that really helps me figure out which
direction I need to take. Onto a sort of related topic...during the
day, I was also working on a script which gives me easier access to
variables in the URL. So far I have:
<script language="JavaS cript">

var variablesInUrl;
var vArray = new Array();

function loadUrlVariable s()
{
varString = location.search ;
//removes ? from varString
varString = varString.subst ring(1,varStrin g.length);
//split into array containing variable=value
variableArray = varString.split ('&');
variablesInUrl = variableArray.l ength-1

for (i=0; i<= variablesInUrl ; i++)
{
temp = variableArray[i].split("=");
vArray[i] = new Array();
vArray[i][0] = temp[0];
vArray[i][1] = temp[1];
}
}

//function returns variable's value
function getValue(varNam e)
{
for (i=0; i<=variablesInU rl; i++)
{
if (vArray[i][0] == varName)
return vArray[i][1]
}
alert ("Variable: "+varName+" was not found.")
}

loadUrlVariable s()

//get value of a variable named step
alert( getValue("step" ) )

</script>

This works okay for pulling variables out of the URL, but I have a few
questions.

- Is it possible to have the script get the variables from the URL and
turn them into your typical javascript variables? By this I mean, say
the URL has ?step=1&name=An dy. Instead of using my script and saying
getValue("step" ), is it possible to have javascript create a global
variable named step with a value of 1? Using my getValue function works
okay, but is not ideal.

Thanks,
Andrew V. Romero

Jul 20 '05 #6
"Andrew V. Romero" <rr*******@icqm ail.com> wrote in message
news:3F******** ******@icqmail. com...
As you mentioned, I would be ideal to do this sort of project
using PHP, unfortunately, my place of emoployment does not have
PHP installed and is not interested in installing it. ...
Short of funds? ;-)

Incidentally, if this is for an intranet and thus for internal use in a
known range of browsers with JavaScript enabled it would be helpful if
you said so because that would make life much easier. (i.e. we could
stop hassling you about reliability, fall-back and limited browser
support and concentrate on what will work in the browsers that you are
writing for.)

<snip> - Is it possible to have the script get the variables from the
URL and turn them into your typical javascript variables? ...


Possible but probably unwise as the global context already has quite a
range of properties and a naming conflict could have all sorts of
consequences. To find out how to use the string held in a variable as
the name of a global property (In JavaScript global variables are
properties of the global (window) object) go to the group FAQ and follow
the link from section 4.39, that page has a section on
creating/accessing global variables in this way:-

<URL: http://jibbering.com/faq/#4_39 >

The code I posted executes a very similar procedure to your getValue
function but it places the name=value pairs into named properties of a
globally accessible object. It also has the advantage that it places all
of the name=value pairs in that object in one operation executed in-line
as the page loads (location.searc h will always be available at that
point). So it does not need to repeat the string and array manipulation
for each function call. Very few property names, such as 'constructor',
'prototype' and 'toString', risk conflicting with existing object
properties and many of those will also exist in the global context
anyway.

Richard.
Jul 20 '05 #7

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

Similar topics

37
4899
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours, Pujo
4
4677
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3880
by: * ProteanThread * | last post by:
but depends upon the clique: http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=954drf%24oca%241%40agate.berkeley.edu&rnum=2&prev=/groups%3Fq%3D%2522cross%2Bposting%2Bversus%2Bmulti%2Bposting%2522%26ie%3DUTF-8%26oe%3DUTF-8%26hl%3Den ...
0
3789
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black and white CCITT4 compressed files (frames) inside the tiff. Every now and then I receive a mixture of black and white CCITT4 and JPEG compressed files, and sometimes just multi-page tiffs with JPEG only. The code runs great when dealing with the...
6
8183
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
4
17878
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the problem is the charset? How I can avoid this warning? But the worst thing isn't the warning, but that the program doesn't work! The program execute all other operations well, but it don't print the converted letters: for example, in the string...
5
6000
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a TIFF to several PNG files this causes a problem, becuase the resulting image is (the page to the far left and a lot of black space surrounding it and a filesize that is larger than needed. Any ideas?
5
5768
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone know a good place to start looking for some theory on the subject of multi user applications? I know only bits and pieces, like about transactions, but a compendium of possible approches to multi user programming would be very appreciated!
0
2329
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing Systems (MuCoCoS'08) Barcelona, Spain, March 4 - 7, 2008; in conjunction with CISIS'08. <http://www.par.univie.ac.at/~pllana/mucocos08> *********************************************************************** Context
1
9320
by: mknoll217 | last post by:
I am recieving this error from my code: The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part identifier "PAR.UniqueID" could not be bound. The multi-part identifier "PAR.PAR_Status" could not be bound. The multi-part identifier "Salary.New_Salary" could not be bound. The multi-part identifier "Salary.UniqueID" could not be bound. The multi-part...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.