JQuery :: Use "this" Event Which Has Been Passed To A Function As A Parameter?

Aug 11, 2009

I have a link;

<a href="javascript:{}" onclick="DoSomething(this)">click me</a> And what i'd like to do is use the "this" object to manipulate the css of its parent;

function DoSomething(obj) {
if(obj) {
$(obj).parent.addClass("newstyle");[code]...

Does anyone know how to do this with jquery?

View 2 Replies


ADVERTISEMENT

Cannot Get Method Argument Passed As Function Parameter

Dec 1, 2011

New to JS. Have ordered some new books, but need to get somethings going in the mean time. What I wanted to do is to link to a new page having a date range input in the form of 6 text boxes, 2 sets of mm-dd-yy, from and to, where the upon loading the page box 1 of the from would auto focus and then auto tab and then post where php could take over on the server side. Setting up the form and the lay out, no problem. Auto focusing went just like expected using the following code, included because on the next step everything fell apart.

Code:
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>

So then the wheels came off and in response, began to simplify what was trying to be done to find where the issues were. As far as I can get working is:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>
<script type="text/javascript" >
function myFunc() {
alert("is this working");
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc()" maxlength="2" value="type a No." />
</body>
</html>

First issue with this: When I first get to the page everything is just as ordered. The focus is on the text box and the default value is "type a No." When I press a key onkeyup, I bring up the alert box with "is this working" in it. But when I refresh the page with the refresh button, after clicking the "ok" on the alert box, the character that was typed in is still displayed. If I use the link to the page, or the URL from the address bar, then the page reloads properly with the default value, "type a No".

How do you get the default textbox value using the refresh button as apposed to reloading the page using a link or from the address bar? Using Firefox 8.0 more important at the moment: If I change the script to pass an argument to the function the script crashes. It does not pull up an alert box and freezes. My guess is that I'm doing something wrong on a concept level. Changed the default value of the text box to " ". Looked like to me there was an issue with the size specification and the default string length as you could only enter in a key stroke by highlighting the text and replacing it.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL]">
<html>
<head>
<script type="text/javascript" >
window.onload=function() {
document.getElementById("input1").focus();
}
</script>
<script type="text/javascript" >
function myFunc(awe) {
alert(awe);
}
</script>
</head>
<body>
<input id="input1" name="input1" type="text" onkeyup="myFunc("123")" maxlength="2" value="" />
</body>
</html>

View 1 Replies View Related

Parameter MyDIVnode.firstChild.nodeValue Not Passed To Function

Oct 1, 2006

why this parameter is not passed to function ?

var myDIVnode1 = document.createElement("DIV");
// etc
myDIVnode1.appendChild(document.createTextNode("a"));
// this shows "a"
alert(myDIVnode1.firstChild.nodeValue);

myDIVnode1.onclick= function() { somefunc(myDIVnode.firstChild.nodeValue); };

function somefunc(param)
{
// this returns "undefined" !!??
alert(param);
}

View 4 Replies View Related

Jquery :: Syntax To Use ID Passed In Parameter Refer To DIV

Dec 24, 2009

I'm passing the id of a div as a parameter. I'm not sure how to refer to it with Jquery. The following does not work:
Code:
function updatemail(param1, param2) {
$("#param2").animate({ opacity: "show" }, 300);
}
I also tried $(param2) but it did not work.

View 2 Replies View Related

JQuery :: Pass A Parameter When Set The Function For An Event?

Jan 22, 2010

Ok this is my first day with JQuery, so I know I'm probably asking a stupid question; But, given the following code, how do I pass a parameter when I set the function for an event.

var url = $("#deleteBlog").attr("href");
$("#deleteBlog").click(deleteBlog);

View 2 Replies View Related

JQuery :: Matching Passed Parameter To Image Map Areas

Aug 23, 2010

I am trying to match a passed parameter on a url to an area on an image map. So far I can find the correct area using
Code:
$('#mediummap area').each(function(i){
href = $(this).attr('href');
if (href == id) {
alert('Found ID ' + id);
}});}});

But next I need to retrieve the co-ordinates for the Area. I have tried
Code:
coords = $('this').attr('coords');
And
Code:
coords = $('this').coords();

I can not seem to get the value back, just an undefined return. What I want to do is to find the point on the image map and then centre that point with in the viewport for the image (large image, small viewport).

View 1 Replies View Related

Change Img Src With Passed Html Parameter?

Feb 1, 2010

I have downloaded 2 html pages that give me page1 with a drop down box for a list, and a 'show' button. this then passes dropdown value to page2 and JS presents the text on the page, but I want to use the passed parameter to change the src of an img with ID=img1.can post all the JS if you like but assume i am missing just a one liner replacing the ....

var name = getValue("name");
document.write(name);

View 4 Replies View Related

XML Document Passed As Jsp Parameter In Javascript Ok With Mozilla, Not In IE!!

Sep 27, 2007

I have a strange problem... I have a form with a text area that contains an XML document. This document can be modified by the user.

Once the document has been modified, the user pressed the "Submit" button to submit the modification (onclick=modify())... and go to another jsp page.... in my javascript, I have the following code:

function modify()
{
myRand=parseInt(Math.random()*99999999); // cache buster
var docXML=document.forms[0].xml.value;
var plist="myRand="+myRand+"&docXML="+escape(docXML);
url="modify_xml.jsp?"+plist;
document.forms[0].action=url;
document.forms[0].submit();
}


With Firefox, the problem does not occur.... but with Explorer, the form is not even submitted!!!!! Is there a workaround for this? The XML document is not even very big.

View 7 Replies View Related

Redirect A User To Another Page While Keeping The Passed In #parameter?

Aug 20, 2009

I posted a similar thread about this in the .NET forum, but I thought maybe there was a javascript way of doing what I need to do.Is there a way to redirect a user to another page while keeping the passed in #parameter?For example, if the user clicks the link:

page1.html#event1

Can I redirect to:

page2.html#event1

Basically keeping the #parameter in tact?

View 1 Replies View Related

Set An Onclick Event Handler To Call A Function Which Requires A Parameter?

Jun 11, 2011

Is it possible to set an html element's (created through HTML DOM's createElement() method) 'onclick' attribute's value to a Javascript function which requires a parameter, passing a variable to it at the same time?

I have the following Javascript code:

var parentDiv = document.getElementById("subscribers");
var stubSpan = document.createElement("span");
stubSpan.id = "opentok_subscriber_" + stream.streamId;
stubSpan.onclick = showStreamInFullScreenMode(stream);
parentDiv.appendChild(stubSpan);

'stream' in the bolded line is a parameter variable of the function that the above code is in, and I'm trying to pass it to another function using an onclick event.

View 2 Replies View Related

JQuery :: Make Event Happen After A Certain Amount Of Time Has Passed?

Aug 6, 2009

After a user hasn't triggered an event for a given amount of purple,would it be possible to trigger that event anyway?

View 6 Replies View Related

JQuery :: Function That Is Being Passed An Array Of Nodes ?

Nov 20, 2010

This is the first question I couldn't find answered by Google! No doubt the answer is out there, but...

So I have a function that is being passed an array of nodes: some of them plain vanilla DOM nodes, (say, those created by document.createElement), others are jQuery nodes (say $("<div></div>").

What's the best way to determine if a node is of each type? I can obviously look at the node contents, but I wondered if there was a "best practices" here?

View 3 Replies View Related

JQuery :: Using Ajax For Passed Argument To PHP Function?

Aug 3, 2011

How I use $.ajax() for passed argument to php function other file example index.php.

View 1 Replies View Related

JQuery :: Using Var Passed To Function To Reference An Object?

Mar 27, 2010

I have just started using the data functions in jQuery for keeping track of a few items on the client. The user can click on links, which call a function that updates the display and stored data value.I am storing data as a set of columns, named c1, c2, c3 etc.

I update the relevant column like this
function UpdateCol(column)
{

[code]....

View 1 Replies View Related

JQuery :: Get $(this) To Work In A Function That Has To Have Variables Passed To

Apr 28, 2011

I want to call a javascript function when a <span> is clicked, pass two variables to it, and then use jquery to hide that span.

A simple example is:

The variables (1,3) & (8,9) are loaded dynamically with a php script. Adding the two variables together isn't the intent of the script, but it seems the simplest way to explain what i'm after.

So how do you get $(this) to work in a function that has to have variables passed to it?

View 6 Replies View Related

JQuery :: Pass Parameter Into Click Event?

Jan 19, 2011

how to pass parameter into click event?

<script>
$(document).ready(function() {
var arr = new Array('link one', 'link two');
for (var i = 0; i < arr.length; i++) {

[Code].....

View 1 Replies View Related

JQuery :: Call Back Function - Should The 1st Parameter Of The Get Function Be A HTML File

Jun 23, 2010

I have just started learning JQuery and have a doubt in the below code. $.get('myhtmlpage.html', myCallBack);The doubt is should the 1st parameter of the get function be a HTML file or can it be a unction name?

View 1 Replies View Related

JQuery :: Set An Onclick Event With Passing A Variable As A Parameter?

Mar 20, 2011

what i want to do-

$
(
"#temp"
).

[Code]....

View 1 Replies View Related

Nothing Is Being Passed Into The Function When It's Being Called?

Jul 31, 2011

I've come across functions like the one below in many scripts.I just don't understand the purpose of the parameter! Nothing is being passed into the function when it's being called- so what's the point of specifying an argument???

function doSomething(e) {
if (!e) var e = window.event;
alert(e.type);[code].....

View 8 Replies View Related

ID Not Being Passed To Function Undefined

Jul 9, 2009

I am making a drop down menu in javascript using a function in an external js file. Problem is in FF error console it keeps coming up that my ID that's being called in getElementByID in the function is not defined. Please help if you can, why is saying my ID is undefined??

View 2 Replies View Related

Cant Use Passed Variables In Function

Oct 11, 2010

I'm trying to reuse a script I have but, I'm not able to due to the fact I can't use some variables in a function.

I would like to know why I am not able to use passed variables in javascript.

For example: I call a function submit_data( 'newDomainForm', 'add_domain', 'list_div' ), in the function itself I would like to use the form name (first variable passed) as document.form.domain_name.value.

Later on I would like to use the div id: list_div in document.getElementById( div_id ).innerHTML. This doesn't work.

I have to put the name of the actual div like this: document.getElementById( 'result' ).innerHTML

And to get the value of a form element I have to put the actual name like this:

HTML Code:

View 9 Replies View Related

Variable Not Being Passed When Calling Function?

Aug 13, 2009

The code below is the relevant part to an autosuggest feature. The variable that isn't being passed is "firstValidIndex". It is being set appropriately, but when it is used in "sortArray()", its value is 0.

// here we must check to see if where the string matched was at the beginning of a string inside this.aNames
// firstValidIndex is the first index where the char is at the beginning of a string

[Code].....

View 5 Replies View Related

JQuery :: POssible To Pass ID As A Parameter For A Function?

Mar 23, 2011

I've been struggling with a piece of code. I'm guessing the solution is quite simple, but I just can't find it! [code]...

The line that I commented out was an attempt at getting a variable that had the value of the image-id, but it doesn't work.

View 4 Replies View Related

JQuery :: Pass More Than 1 Parameter To Click Function?

Jun 10, 2010

I currently have the following:

<a href="#" id='$dbase'>Link</a>

which passes the value of $dbase to my jQuery click function.

But I'd like to also pass a second parameter consisting of a page number. Can that be done using the click function or would I have to do it another way. I'm assuming it must be possible. I suppose i could always concatenate the two parameters, e.g. $dbase-$pagenum, pass that and then split it in the javascript but that seems a slightly inelegant way of doing it.

View 2 Replies View Related

JQuery :: Can't Pass Function As A Parameter And Call It

Aug 2, 2011

I'm trying to pass locally defined function as aparameter. Every time I do it, it causes an error saying something along the lines of "there is no conversion for text to function".

$(document).ready(function(){
jQuery("#confirm-ajax-submit").click(function(event){
var success = function(){
alert("this is what I want to see.");

[Code].....

View 5 Replies View Related

JQuery :: Function As Parameter Data In Requests?

Oct 20, 2011

I'm using jQuery Validate to validate my on-line things.it looks like a plugin issue, but my turn-arround was on ajax/param not on the plugin, so i put it on core.Today i faced a problem, that is: i use remote validation and i needed that all the form is submited to the validation. (this remote validation is like a bridge to the $.ajax)i have tried this, and of it is not the best deal, because it get the form on ready and don't change when the form change:

$('#nome').rules('add',
{
remote:

[code]....

View 4 Replies View Related







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