Solved

return input data to another function

Posted on 2014-02-12
12
251 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

695 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