Solved

return input data to another function

Posted on 2014-02-12
12
246 Views
Last Modified: 2014-02-12
Hello
Brand new to JavaScript1 - my question is how can I pass a value from my input box to another function - see "PASS_ID=7456" in 2nd script tag. I would like whatever value is put in the input box to replacethe value 7456
see below for my code..
<script>
function myFunction()
{
var x;
var person=prompt("Please enter your ID","?");
if (person!=null)
  {
  x="You chose.. " + person + "!";
  document.getElementById("demo").innerHTML=x;
  }
}
</script>


<script>
function dashboard1()
{
window.location.assign("http://test/views/Summary?:embed=y&:display_count=no:PASS_ID=7456")	
}
</script>

Open in new window


Regards
0
Comment
Question by:PHIL Sawyer
  • 5
  • 4
  • 3
12 Comments
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 400 total points
ID: 39852864
Just pass the variable to your function dashboad1 and use it to set the location
function myFunction() {
	var person = prompt("Please enter your ID", "?");
	if (person != null) {
		document.getElementById("demo").innerHTML = "You chose.. " + person + "!";
		dashboard1(person);
	}
}
function dashboard1(personID) {
	window.location.assign("http://test/views/Summary?:embed=y&:display_count=no:PASS_ID=" + personID);
}

Open in new window

0
 

Author Comment

by:PHIL Sawyer
ID: 39852912
This works great thanks!
I tried adding another button so my dashboard could take another variable but when I use the first button and OK it goes staright away to my site before I can use the second button.
Any pointers for me please.

Regards
0
 
LVL 25

Expert Comment

by:devic
ID: 39852975
hi philipsivyer,

default button behavior is to submit the form data. If you need to do something else before submit the form, you need add 'return false'

e.g.  <button onclick="someFunction(1);return false">one</button>
0
 

Author Comment

by:PHIL Sawyer
ID: 39853046
If I use another button as
<button onclick="myFunction2();return false">Click</button>
.. it still activates my site prior to using second button?
Regards
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 39853079
returning false or not; the location of the current window is re-assigned...
In order to understand what you want, you have to be more specific. You could post some code and explain what you want to achieve.
0
 

Author Comment

by:PHIL Sawyer
ID: 39853112
Here is the code..
<p>Click the button to prompt for First Fund_ID?.</p>
<button onclick="myFunction();return false">Click</button>
<p id="demo"></p>
<script>
function myFunction() {
  var person = prompt("Please enter your ID", "?");
  if (person != null) {
    document.getElementById("demo").innerHTML = "You chose.. " + person + "!";
    dashboard1(person);
  }
}
</script>


<p>Click the button to prompt for Fund_ID?.</p>
<button onclick="myFunction2()">Click</button>
<p id="demo2"></p>
<script>
function myFunction2() {
  var person2 = prompt("Please enter your ID", "?");
  if (person2 != null) {
    document.getElementById("demo2").innerHTML = "You chose.. " + person2 + "!";
    dashboard1(person2);
  }
}
</script>


<script>
function dashboard1(personID)
{  
window.location.assign("http://sss:8000/views/DASHBOARDS/Summary?Fund_ID="+ personID)      
}
</script>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 39853169
OK.
You press the button and it executes myFunction.
If you type a name and press OK it executes dashboard1 and then the location is being re-assigned.

What is it you're trying to achieve ?
0
 
LVL 25

Expert Comment

by:devic
ID: 39853180
As AlbertVanHalen wrote you are trying to change location.
You need to decide first what you want to do?

change location is equal  abort everything and go to a new location

as possible solution can be navigating to an iframe or make a new ajax request.

So you need first decide what you are trying to do.
0
 

Author Comment

by:PHIL Sawyer
ID: 39853182
OK - I want to enter a value (button1) then enter another value for (button2)
then my site gets activated (dashboard1). At the moment when I enter a vlaue re button 1 then my site opens prior to me activating button 2.
Regards
0
 
LVL 25

Assisted Solution

by:devic
devic earned 100 total points
ID: 39853230
according your code
1. enter a value (button1)
2. then your myFunction calls dashboard1
and dashboard1 aborts everything and opens a new page.

if your function will open a new window, or navigates to an iframe or make a new ajax request, then your code will run.

e.g. try a new window

function dashboard1(personID)
{  
window.open("http://sss:8000/views/DASHBOARDS/Summary?Fund_ID="+ personID)      
}

in this case will be opened a new window, but your script will run next instructions
0
 

Author Comment

by:PHIL Sawyer
ID: 39853427
OK - got it
Thanks for both of your help
0
 
LVL 19

Expert Comment

by:Albert Van Halen
ID: 39853540
Thanks.
Hope you get it working like you want.
Good luck !
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now