Forms - Functions And Variable Declaration

May 28, 2009

I have been having trouble with forms and functions. On my wife's site I have some forms and some of them have radio buttons. My current radio button checker is cumbersome and it is time for something more elegant (some of you will say if it isn't broke don't fix it )

The new code is below:

Code:

Basically I want to pass into the function radio button values 1 & 2 denoted by firstChoice and secondChoice (eventually I want to also pass in the form name but 1 step at a time).

The buttons can have the value (names?) of pattern, chalkboard or kit. It is for a shopping cart (Mal's E-commerce) and this is part of the JS validation. I am using onsubmit to call the function viz.

HTML Code:

Seems ok (to me at least) but when I try to get it to work it throws up an error of

Code:

It stops at that point but undoubtably chalkboard would throw up the same error if it continued.

How would I define the variables in my function? Are they strings, integers, who cares?
Where would I define them? Global or local?

Is the problem a matter of syntax e.g. if I put ' ' or " " around them would that suffice?

View 10 Replies


ADVERTISEMENT

Variable Declaration Issue

Jun 20, 2007

i did not undestand weather 'var' Keyword should be used or not when declaring variables. i already familier with php and there i will not use a 'var' for variable declaration. i like to program JS using similler PHP sysntax. so i code JS with out 'var' for varialb declarations and it works.

but can you please tell is it ok to declare variables with out the key word 'var'? if this is not good, then do all global and local variable declarations requir 'var'?

View 2 Replies View Related

Initialize A Variable At The Point Of Declaration Or Not

Feb 8, 2009

I understand that there is no need to initialize a variable at the point of declaration. OTH, what is the default type of a [declared] variable? For example:

[Code]...

View 15 Replies View Related

Variable Declaration - Add Html Code As A Var Or A Const

Apr 9, 2011

I want to add this html code as a var or a const, so then later I could do document.write(x);

Like:

But this do not work.

View 3 Replies View Related

Variable Declaration - Specify Arguments When Writing A Function

May 11, 2011

If you specify arguments when writing a function should you still declare the argument variable inside the function?

example:

Code:

or

Code:

View 8 Replies View Related

Cannot Access Global Variable Inside Object Declaration

May 9, 2011

Well, it turns out IE8 has yet another problem. My code has a global variable (to the object) inside an object declaration that cannot be accessed by a function (that is also global).

The code is like so:
Code:
function myobject(params){
//public
this.initialize = function(){...}
//private
some variables...
//problem variable
var mouse = new Object()
mouse.x = 0;
mouse.y = 0;

//code...
slidecontainer = document.createElement("div");
slidecontainer.onmousemove = function(event) {
if(boo.isIE) {
e = window.event;
mouse.x = e.x + document.body.scrollLeft;
mouse.y = e.y + document.body.scrollTop;
} else {
e = event;
mouse.x = e.clientX + document.body.scrollLeft;
mouse.y = e.clientY + document.body.scrollTop;}}

//this function is in an interval
function moveslides() {
/* this is where I have the problem

It seems that the function doesn't recognize that mouse.x, or mouse for that matter, exists. Mouse is global to the object, so why can't this function access it?
*/if(mouse.x) {
code...
}}}
The page is at [URL] and works on every browser, including finnicky opera, except for ie. The full code is availabe when you right click and view the source on the page.

View 3 Replies View Related

Calling Functions Using Forms

Mar 25, 2006

I've created a selection box (drop down box) with several options for the user to click. What I want is if the user clicks a certain box, then a specific javascript function will run. BTW, I am using Google Maps API here. Code:

View 1 Replies View Related

If Statement With Forms And Functions?

Sep 11, 2010

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

[code]....

View 1 Replies View Related

Clear Checkbox Functions - Multiple Forms

Nov 2, 2011

I posted a thread a few days ago concerning a bit of javascript code to make checking one checkbox clear another one. I got some great, prompt help. However, I just got back to working on that web page, and realized that the functions only work on the first form on my web page. I have many forms and they are actively named using php.

Here's are the functions (these works for just the first form on the page):

<script type="text/javascript">
function undo_Changes() {
if (document.getElementById("Complete").checked==true) {
document.getElementById("Needs_Change").checked=false;

[Code]....

View 6 Replies View Related

ChangeYear - GetFullYear - SetFullYear Functions - Extract The 4-digit Value From The Today Variable And Store The Value In A Variable Named Year

Oct 13, 2009

a.) specify two parameters for the changeYear function: today and holiday.

function changeYear(today)(holiday){

b.) in the first line of the above function, use the getFullYear() date method to extract the 4-digit value from the today variable and store the value in a variable named year.

first line

c.) in the second line; use the setFullYear() date method to set the full year of the holiday date object to the value of the year variable.

second line

d.) in the third line, use a conditional operator on the year variable. The test condition is whether the value of the holiday date object is less than the today date object. If it is, this means that the event has already passed in the current year and the value of the year variable should be increased by 1.

third line

e.) in the fourth line of the function, again set the full year value of the holiday date object to the value of the year variable.

View 3 Replies View Related

Dynamic Forms And Updating On Reload, Inserting Functions, Jumping Text?

Jan 12, 2010

I'm trying to create a dynamic form, and for the most part it's working out fine.I'm using javascript with onclick and onchange on checkboxes and select boxes to change the form as the user makes selections.However, there's a few issues I'm running into that are giving me problems.

One is that when the user reloads the page, all of the javascript inserted or removed form elements are reset, but the choices on the checkboxes and select boxes aren't, which looks very strange to the user. How can I avoid this? I'm currently including scripts tags in the body of the html, but this is pretty messy and hard to manage. Is there a better way? Second is that I'd like to be able to insert javascript function declarations into text that is dynamically inserted by javascript.However, when I do so, the browser does not recognize the functions. The reason I'd like to do so is that I am using Ruby on Rails, and would like to be able to keep the scripts in the partials to which they relate. I have to use inline javascript, because the scripts are having element ids inserted based on Ruby variables. Is this a lost cause, or is there a technique that enables dynamically inserted javascript to be loaded?

Lastly, my dynamic form's javascript shows or hides portions based on what it encounters while loading. The main reason is that I want to show the whole form for users without javascript, and then hide advanced or obscure details unless they are activated with a checkbox on the form for users with javascript. However, this is creating a jarring pop-in effect, where on first load, the pre-javascript formatted page is shown for a split second, and then the javascript kicks in and fixes everything and the page visibly jumps and changes. Is there a way to avoid this to create a more polished effect?

View 3 Replies View Related

Variable Declaration Inside Eval Inside With

Apr 11, 2007

consider the next code:

var obj = {};
with(obj) {
var x = 10;
}
print(x);
print(obj.x);

It prints 10 and undefined. Here, one could expect that obj.x get the
value 10. But it's not the case, because variable declarations are
placed at the start of function code (or global code), so the
previous code is equivalent with:

var obj;
var x;
obj = {};
with(obj) {
x = 10;
}
print(x);
print(obj.x);

You can clearly see now that x is placed in the outer context. But
consider the next:

var obj = {};
with(obj) {
eval("var x = 10;");
}
print(x);
print(obj.x);

I was expecting that obj.x would get the value 10 here. But no, it
gives the same output as the previous code. I tested it with
spidermonkey, kjs and ie jscript. Looking at the ECMA spec, I could
not find anything that describes that behaviour. Code:

View 3 Replies View Related

Using Variable To Control Two Functions

Aug 11, 2011

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>JS: Image Slider</title>
<script type="text/javascript">
[Code]....

My problem is that every other turn I have to click either button twice to start the desired function. Say, I autoplay the images first and I want to shuffle them, I click shuffle and the autoplay stops working and I need to click shuffle again and then the shuffle runs. How can I make it clicked once and the function runs?

View 1 Replies View Related

Variables And HTML Forms - Use A Variable In The Aforementioned If Statements The Failed To Work?

Sep 1, 2011

Currently I have the following script:-

function validate_form(){
if(regform.reguser.value == ""){
alert("Please completed the selected box");[code]....

to validate a simple registration form, however I initially tried to streamline this function by cycling through an array using a loop to point to various input elements in the HTML page itself. I found that when trying to use a variable in the aforementioned if statements the javascript failed to work i.e.

var test = "reguser";
if(regform.test.value = ""){
}

I know the javascript is looking for the input element "test" instead of "reguser" but is there any way I can force it to look for the contents of the variable.

View 2 Replies View Related

Moving Variable Inside Functions ?

Jun 6, 2009

I have a problem that 'test' is not passed. The following function alert undefined, but it should alert test. Why that?

PHP Code:

View 1 Replies View Related

Make A Variable Available To Other Functions Outside A Function?

Feb 12, 2010

Is it possible to make a variable available to other functions outside a function So to make it global from within a function without using a callback

function() {
var something = 'hello';
}
function(something) {
document.write(something);
}

something like that possible??

View 1 Replies View Related

Local Variable In Multi Functions?

May 20, 2011

i'm having the following problem, normaly i work with html css and php but for this to work i need to make a litle javascript function and i'm still kinda new to it. so here is my problem.i'm making a search field where someone has to select some radiobuttons.first it has a selection out of 4 items and then a selection out of like 20 but how do i get the value from the first function in the second?in this case i would like to have the following in function showStreek:

xmlhttp.open("GET","test3.php?l="+land,true);
this line should look like:
xmlhttp.open("GET","test3.php?k="+kleur"l="+land,true);

[code]....

View 5 Replies View Related

Call Functions From (string) Variable?

Nov 14, 2005

How can I call functions from the value of a variable?

I do this in PHP, like $variable(); or {$variable . 'CallBack'} or using something like call_user_func().

I've been search all day though, and can't find how to do this in javascript. Is it possible?

View 5 Replies View Related

Objects, Callback Functions And Variable Scope

Nov 23, 2005

I am trying to convert some of my javascripts into a class and am
running into difficulties which i think are related to variable scope.

Basically I have a constructor function for a calendarInput class that
takes 4 parameters, the first is a reference name/number for this
input. I also have some functions for importing my PHP classes into
Javascript using AJAX (properties only. still trying to get methods
working but that's another story!). The relevant function is called
call_object_method(classname, methodname, createparams, methodparams,
post, callbackfunction). This creates an instance of the specified PHP
class using the parameters in createparams. It then calls the
specified method using the parameters in methodparams. The result is
passed back to the javascript function specified in the callbackfunction parameter (ie the value of xmlhttp.onreadystatechange is set to callbackfunction before xmlhttp.send() is called)

The function i am trying to fix is called show (x,y) which creates the
html for the calendarInput and displays it at co-ordinates x, y.

So, my code is as follows:

function calendarInput(calendarid, target, displaytarget, value)
{
this.calendarid = calendarid;
this.target = target;
this.displaytarget = displaytarget;
this.value = value;

this.show = function(x, y)
{
<!--// bunch of init and prepping code. includes creating
createparams and methodparams arrays //-->

call_object_method("cms_calendar", "getcalendarview",
createparams, methodparams, false, this.showcallback);

}

this.showcallback = function()
{
alert(this);
<!--//code to create html//-->
}

}

I know i've cut out most of the innards of this. This is because I
have already tested these functions and had the calendarInput working
outside of a class, hence am pretty sure that this is ok (plus it runs
to almost 1000 lines these days!!). My problem is that when I call the
show method, the alert on the first line of the callback function
returns the function showcallback instead of (as i was expecting) the
instance of the calendarInput object. Whilst this kinda makes sense I
can't figure out how to reference the Object instead. I have tried
'this.parent' but this returned undefined. I have tried changing the
way i reference the callback function (ie the final parameter of
call_object_method) but no joy.

View 2 Replies View Related

JQuery :: Functions With Variable Number Of Arguments?

Jul 26, 2011

So in the Tutorials:How jQuery Works, I've noticed that you can make a call to .get like this : $.get('myhtmlpage.html', myCallBack);

I've also noticed that in the docs jQuery.get() is described as jQuery.get( url, [data,] [success(data, textStatus, jqXHR),] [dataType] ). My question is, in the above example, the callback function is the second argument, whereas in the docs the second argument is data, and the third is the callback function. How does this work? Also, what does it mean when the arguments are laid out in an array-like fashion with commas in the square brackets? i.e. arg1, [arg2,]...

View 4 Replies View Related

JQuery :: Variable Scope And Un-named Functions?

Aug 23, 2010

I've recently started developing javascript using jQuery and so far I'm really enjoying it.Being a professional programmer (mainly C, C++, java and python) there is one thing that's been puzzling me regarding variable scope and unnamed function declarations. Let me exemplify:

------------------------
var sum = 0;
$(xmlobj).find("item").each(function(){

[code]....

View 6 Replies View Related

Watch Variable Values Inside Functions?

Jul 2, 2010

Is there any way we can watch variable values inside javascript functions while running through the debugger. I am using javascript along with ASP.net on Visual studio 2010.

View 2 Replies View Related

Moving Variable Inside Functions - Alert Undefined ?

Jun 7, 2009

I have a problem that 'test' is not passed. The following function alert undefined, but it should alert test. Why that?

View 1 Replies View Related

Variable Scope - Anonymous Functions And Self Invoking Closures

Jul 25, 2011

I think the last thing people seem to learn about in JavaScript when they're not coming from other programming languages is variable scope. Some even get all the way into AJAX without having learned about scope, and this is a time when it's really needed. Although the scope of JavaScript variables is non-complex by nature, it's something we should all get a full understanding for before we move too far.
Section 1: What is "scope"?
Section 2: The "var" keyword
Section 3: The "this" keyword
Section 4: Closures or "Anonymous functions and self-invoking closures

View 5 Replies View Related

JQuery :: Dynamically Declaring Functions - 'array' Variable Contains Strings Representing The Id's Of Different Elements

Oct 12, 2010

Demonstration code:

The 'array' variable contains strings representing the id's of different elements. If the for loop above were to finish iterating, would all the links in all three elements call the click function (that displays an alert message), or would only the last element ("element3") have the click function? For me, the latter seems to be the case unless if I'm doing something wrong, but I would like clarifications and, if possible, alternative solutions as to how I can achieve the former result.

View 1 Replies View Related

Make Few Forms But 1 Submit Button - Send The 5 Forms As 1 Form

Sep 16, 2010

I want to make few forms but 1 submit button. I want to do 1 page , 5 forms , 1 submit button so when i click on the submit button it will send the 5 forms as 1 form.

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved