[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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
0
PHIL Sawyer
Asked:
PHIL Sawyer
  • 5
  • 4
  • 3
2 Solutions
 
Albert Van HalenCommented:
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
 
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 HalenCommented:
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 HalenCommented:
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 HalenCommented:
Thanks.
Hope you get it working like you want.
Good luck !
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 5
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now