return input data to another function

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
PHIL SawyerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Albert Van HalenAnalyst developerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PHIL SawyerAuthor Commented:
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
devicCommented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PHIL SawyerAuthor Commented:
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
Albert Van HalenAnalyst developerCommented:
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
PHIL SawyerAuthor Commented:
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
Albert Van HalenAnalyst developerCommented:
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
devicCommented:
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
PHIL SawyerAuthor Commented:
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
devicCommented:
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
PHIL SawyerAuthor Commented:
OK - got it
Thanks for both of your help
0
Albert Van HalenAnalyst developerCommented:
Thanks.
Hope you get it working like you want.
Good luck !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.