How A Function Return Two Values?
Jul 11, 2006Can javascript using pointer or pass variable by reference?
Or I need to using object or Array to return the two values?
Can javascript using pointer or pass variable by reference?
Or I need to using object or Array to return the two values?
I am trying to build an interface to upload files and change some of the form (hidden) values depending on the file uploaded, here is where I got so far:
$('#buttonUpload').click(function (){
$.ajaxFileUpload({
url:'doajaxfileupload.php',
secureuri:false,
fileElementId:'fileToUpload',
dataType: 'txt',
[Code]....
My problem is that I want doajaxfileupload.php to return a variable to javascript/change some html form value. The code works as it is for the file upload, I just need to add something for the output, Edit: I just noticed that some previous part of the code is still there: the part that changes the color of the button depending if the file is uploaded or not. Now I want those values to change depending on what file is uploaded.
Ok so i'm going to try and be as descriptive as possible for this issue is extremely challenging for me to resolve.
I am creating an auto suggest search feature and I decided to do it in OOP.
My current set up is like this..code...
I was looking at some public code for detecting browser version/type as well as the new IE8 compatibility view. The code does a return of multiple values but I can't figure out how to use them in my html code.
I've managed to figure out most of what the code is doing but I haven't figured out how to access the returned information. I've only been coding JavaScript for a short time so I'm stumped.
Here's the code:
CODE:
I have a understanding problem with this:
var loadData = function(){
$.post('/search.php', { myvar: 12345 }, function(data){
$.each(data, function(key, val) {
// here I have to validate my data I retrieved
if(first condition){
return false;
[Code]...
I have a bunch of input fields, each which will have a numerical value. There can be any number of input fields in the form, and that number will vary depending on what the user has selected prior in the application.
So basically I created a loop that goes though all of the INPUT fields within the form. How can I have it find the value of each field and add them all together, then return to me the total? It'll need to be made into a variable, but a simple alert with the total value will give me enough to work with.
i am finding value for a table height in window.onload=function(){
boxheight=document.getElementById('tableid').offsetHeight;
}
i want to assign box height to an outside variable boxheight. Code:
I have a problem with attr() function.I made my own lightbox and with jQuery 1.4.x it works nice. But now I use 1.7 and there is a problem. When I called attr in 1.4 $(element).attr("rel") when element hasn't rel, it returns empty string, but in 1.7 it returns undefined.Why? I read a changelog and I didn't find any change at that function.
View 2 Replies View RelatedThis has me completely stumped. I have a multiple select form element in my HTML document that needs to be manipulated by two different sets of context-sensitive controls. One set of controls is marked up as follows:
<div id="divControls1" name="divControls1" style="display:none">
<form id="fControls1" name="fControls1">
<input type="button" id="btnAdd" name="btnAdd" value="Add" onClick="addStuff();" />
<input type="button" id="btnEdit" name="btnEdit" value="Edit" onClick="editStuff();" disabled />
<input type="button" id="btnDelete" name="btnDelete" value="Delete" onClick="deleteStuff();" disabled />
</form>
</div>
When I load this page into Safari (on Mac OS X) and set the style of divControls1 to "display:block," I have an enabled "Add" button, a disabled "Edit" button, and a disabled "Delete" button, just as I expected. (I monitor selections in a multiple selection element to turn the buttons on and off.) But when I load this page into Firefox (also Mac OS X), all three buttons are disabled at startup. My page runs a function called startup() when the body fires onLoad. To try to troubleshoot the problem, I wrote this line at the beginning of the startup() function:
function startup() {
alert (document.getElementById("btnAdd").disabled);
...
When I run this code in Safari, the alert returns "false" (not disabled), just as I would expect, and intended. However, the same code in Firefox (Mac OS X) returns "true" (disabled) ... but the same code in Firefox (WinXP) returns "false"!
I'm trying to "progressively enhance" one of my surveys using javascript. Basically, I have rating scales that make use of radio buttons as each point on the scale. Each radio button occupies its own cell in a table. I wrote some functions that will highlight cells on mouseover in a color corresponding to its position on the scale (e.g. the lowest point is red, the midpoint is yellow, the highest point is green). When a radio button is clicked, the background of the button's cell and preceding cells in the same row will be colored accordingly. The functions are working well in FireFox and Chrome (I just have to add a few lines using the addEvent function to make it compatible with IE).
The effect looks a lot nicer when I add a function that makes the visibility of the radio buttons hidden.
However, I want to make sure that there is a fallback option in case the functions that color the cells don't work for whatever reason. I would not want the radio buttons hidden in this case.
Is there a method whereby I can call the "hideRadiobuttons" function only if the other functions are successfully executed?
i've got a function which makes a call to the database( via jquery $.post) to check if a username already exists. All the data I get back is fine and both the conditional statment works as intentded. I just can't get the function to return a value to the other function that calls it. Could this be something to do with the scope.
Code:
function checkIfUsername(o)
{
$.post(""+CI_ROOT+"index.php/admin/check_if_username",{
username: username.val()
}, function(data){
if(data.bool == true){
[Code]....
Afternoon all, Have a pretty simple function, that requests a number to be entered.
I want to return that number, but i seem to be typing something wrong in the return value.
function newFunction(a, b)
{
var newArray = new Array(a);
for (var i = 0; i < 5; i = i + 1)
[Code]....
I am populating a field on my page using a php include. I am asking javascript to update another element with that field's value. The value written to the select input box is Ƈ:Any Provider'. The process works fine in Firefox. In IE6 it does not write. the value nor does it throw an error. What am I doing wrong?
input form:
[PHP]<form method="post" action="" name="inputForm">
<label for="provider">Name of Provider</label><select class="input" name="provider" size="1" style="width: 20em"><?php nameprov();?></select>
<input type="button" name="button" value="Upload" onclick="postthis()">
<div id="status"></div>
</form>
The script in the head element:
function postthis(){
var provider = document.inputForm['provider'].value;
var report = document.getElementById("status");
var message="The Value of Provider Block is: " + provider;
report.innerHTML = message;
}
In firefox, "The Value of Provider Block is: 1:Any Provider" is written in the report element. In IE6, "The Value of Provider Block is : " is written in the report element.
I know the answer must be yes, but I am really having a hard time figuring this out. I have a simple script below, that calculates age (I know I need to do some more work). I want to redisplay the value returned from the function. It works OK, because the result displays correctly in the alert. Code:
View 23 Replies View RelatedI have a form and a submit button .on clicking submit button function validate call.this function call another function (say func) .this func function vallidates some input and return true or false value to the validate function this then return true or false value to the submit button .I want that func directly return true or false to the submit button.
View 2 Replies View RelatedHow can I use the return value from prev_picked() in my ajax call?
Code JavaScript:
function autosuggest_results (info)
{
if (info.length > 1)
[Code].....
I have a multiple choice quiz that works fairly well. However, instead of it presenting "End of Quiz" message when last question is completed I need it to take the user back to the beginning (question 1) but with no indication to the user that this has been done. How can I adjust the code to have it do this?
<script language="JavaScript1.1">
var whichone=1
var tempmn=document.quiz.thequestion
function generatequestions(){
document.quiz.theresponse.selectedIndex=0
[Code]...
I want to pass a javascript function's return value, to an anchor tag's href parameter i.e. <a href>
Suppose I have a function called getTrackingCode( ) that contains a value "testSite"
<script language = "JavaScript">
function getTrackingCode( )
{
return "testSite";
}
</script>
Now I want to pass this function's value to anchor's href, I have attempted these:
[Code]...
I have a desire to include more than one return statement in a function I have written so that when it has found the solution to a hit-testing series of conditionals, it returns the solution. The desire is to avoid further hit-tests when solution has been found. I've always felt that more than one return statement in a function is poor style, since it may lead to false execution of a function - by way of a later code edits - making a mistake by forgetting the multiple returns. My function is short and maybe the optimisation exists only in my head but are there serious reasons why one should not have more than return statement? This JS code executes in the Quartz Composer framework and has nothing to do with we programming (context (-:)
Here it is with three returns, it 'works' and I could replace all the break statements with return statements to finish optimizing:
//Test for y inside range for all quads ( Quad is defined by 4 points in a row in the list is a quad ie. list[0-3], list[4-8],
//Test along the unit numerals (_N) and also the 'Revert Patch' button
if (y >a[0]["Y"] && y <a[2]["Y"]) {
for (i=0; i <37; i+=4) {
//Log("DDDDDDD "+i+" X:"+x+" Y:"+y); .....
I've been reading up on Javascript. I read that you can use:
document.write("<h1>My Test</h1>");
So I wrote a little script:
<script type="text/javascript">
var choices = new Array();
choices[0] = "<img src=\"crush.png\" />";
choices[1] = "<img src=\"curse.png\" />";
choices[2] = "<img src=\"endless.png\" />";
choices[3] = "<img src=\"eyes.png\" />";
[Code]...
How do I pass results back to textService so that I can make a call such as textResult = textService(text to pass in);
I don't want to use a global variable if I can avoid it. This is the code
Code:
function textService(text){
req.open("GET", "http://....?text="+text, true);
req.onload = showResults; req.send(null);
}
[Code].....
Basically I would just like these two functions to become one function with a return value.
My function the_magnitude() takes in values from 4 different asp:textboxes. The textboxes "easting" and "northing" contain numbers that don't change, but the textboxes "east" and "north" contain numbers inputed by the user, and the function returns "error" as a value to be put into another textbox that we'll call "error box". So what it's suppose to do is when I update the information in either "east" or"north" it will update, on change, the number in the "error box". It kinda works.My problem is that if the number is a value that changes the style to red, #ff0000,in the function it wont update the "error box" and it just leaves a red zero that is a default number in the box. The only way I can get the number to change is if I end up with a number less than 200, which would make the text green.I'm pretty sure it's a problem with my javascript.here is my function
<script type="text/javascript">
function the_magnitude(easting, east, northing, north, error) {
var a = easting.value;
[code]....
I am relatively new to js, but I did think I was starting to get the
hang of it. Then this happened...
I have a form with an onsubmit event handler:
<form id="uploadForm" method="post" action="..."
onSubmit="checkDates()">
The event handler does some minor validation, then returns true or
false:
function checkDates(y, m, d) {
if (endDate.getTime() >= startDate.getTime())
return true;
alert("Start date must precede end date");
return false;
}
(The arguments to the function are used when it is called elsewhere,
not as onsubmit.)
I also have a library class which needs to process the form submit, so
it hooks onsubmit like this:
MyClass.setOnSubmit = function(listId) {
var list = document.getElementById(listId);
var form = list.form;
var f = form.onsubmit;
if (typeof f == "function") {
form.oldOnSubmit = f;
form.onsubmit = function(){
var ok = this.oldOnSubmit();
if (ok)
return MyClass.onsubmit(listId);
else
return false;
};
}
else
form.onsubmit = function(){MyClass.onsubmit(listId);};
}
My problem is that the value returned from oldOnSubmit and stored in ok
appears as 'void'. This happens in IE 6 and in FireFox 1.07. Can anyone
explain what's happening?
Here's the function:
function getParentElementByTagName(child, TagName){
var cn;
if (child.parentElement){
cn = child.parentElement;
if (child.parentElement.tagName == TagName){
return cn;
}else{
getParentElementByTagName(child.parentElement, TagName);
}}}
although it finds the element, the function returns null ( on the line
'return cn', cn is not null though). Is my algorithm wrong ?
I'm trying to make a call to .ajax and as a result set a value in a hash (for another call to jquery-ui)
I get the data coming back fine, could put in in a text field in html but not the hash where I want it.
Here below are the parts of my code that I'm using
//setting up datepicker
$(courseStartDateHtmlId).datepicker({
.....
defaultDate : ($(courseStartDateHtmlId).val() != "") ?
[Code].....
I thought that the value of startDate would end up as the defaultDate param for datepicker. No luck. Only an obscure little message in firebug console: "missing: before statement"
as I can return a second value of the autocomplete function?
the script
<script type="text/javascript">
$("#nombre").autocomplete("<?php echo base_url()?>transportistas_controller/autocomplete_partidos");
$("#nombre").blur(function(){
[Code]....