[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

return input data to another function

Posted on 2014-02-12
12
Medium Priority
?
253 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 1600 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
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 400 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

649 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