Unobtrusive Script With Parameters?
Nov 12, 2009
I have a PHP page that dynamically generates table rows with input fields. A sample row looks like:
Code:
<tr id="row1">
<td><input type="button" name="remove_row1" id="remove_row1" value="X" /></td>
</tr>
I have a JavaScript function that I am attempting to attach to each of the input buttons:
Code:
// get all the input elements
var inputs = document.getElementsByTagName('input');
var delete_regex = new RegExp('remove_row');[code]...
But I would like to give it a parameter
Code: inputs[i].onclick = delete_row('row' + inputs[i].id.replace('remove_row', ''));
But doing the above just executes the function. What is the best way to do this?
View 2 Replies
ADVERTISEMENT
Jul 10, 2007
I was reading through a book that talked about unobtrusive javascript, and it gave this example of how to trigger a function instead of using an inline onmouseover event handler.
document.getElementById("RandomElementId").onmouseover=RandomFunction;
I thought this would be cool, but I can't seem to find a way to pass parameters to the function this way. I assumed you just use RandomFunction(parameter1,parameter2); but no go.
Is there a different syntax for this, or does this technique forbid using parameters?
View 3 Replies
View Related
Jan 24, 2007
Is it possible to write this as and unobtrusive script in the head of a document?
This is a really long piece of code for being in the html!
<a href="whatever" onmouseover="document.images['s3a'].src='hover.gif'" onmouseout="document.images['s3a'].src='root.gif'" onmousedown="document.images['s3a'].src='active.gif'" onmouseup="document.images['s3a'].src='hover.gif'"><img src="root.gif" name="s3a" height="50" width="50" alt="" border="0"></a>
View 2 Replies
View Related
Mar 3, 2010
First off by let me stating that I am not a great web devloper nor am I a good with css / javascript. I am creating this website for a friend of mines company and I have one problem.The problem is that the navigation menu on the right side will not remain fixed how i want it to be. I spoke with many people and they all said that this cannot be done with css considering your layout and because it needs to dodge the headers and the footer. I basically want this div (sidenav on the right) to scroll along the page as users scroll up or down but it can not interfere with the header or footer. I do not want the right side navigation to go over the content or out of the wrapper. I want it to stay in the same position in all aspects - left / right / top / bottom. Here is a link to the site [URL].
View 2 Replies
View Related
Oct 16, 2007
I have been going back and getting rid of so many of my onclick's and such, trying to switch to a more unobtrusive method of adding events to anchors.
I've run into one snag that's kind of dissonant for me, and wondered if anyone had any advice.
By adding an event, you can turn:
<a href="#" onclick="something(); return false;>Click me</a>
Into:
<a href="new.html" class="something">Click Me</a>
But what goes in href if you don't have anything to actually link to? One example is a page I've written that is entirely self-contained, and all href's that drive the interface end up pointing to #. Is this acceptible in edge cases like these with the unobtrusive approach?
If someone has JS turned off the markup is essentially meaningless, so I was wondering how people deal with this lapse in the separation between behavior and structure.
View 2 Replies
View Related
Jul 11, 2009
I'm working on implementing an unobtrusive javascript where I use code instead of an HTML hook to call a function.
Old way: <input type="text" name="username" onBlur="javascript:function();" />
Now I have changed it to:
window.onload = function()
{
if(document.getElementById("username"))
{
var usernameInput = document.getElementById("username");
usernameInput.onblur = checkUsername('username','ajaxResponse');
}
}
which is placed in the body section of the page. Anyhow, my problem is that it works fine, but only once, right as the page loads. I have tried removing window.onload, but then it doesn't work at all. How can I get this to work every time I blur from the text field?
View 1 Replies
View Related
Jan 10, 2007
I've got the following code in a website of mine:
Code:
<a href="section1.htm">Section 1</a>
<a href="section2.htm">Section 2</a>
<a href="section3.htm">Section 3</a>
<a href="section4.htm">Section 4</a>
<div id="general">General overview</div>
<div id="section1">Section 1 overview</div>
<div id="section2">Section 2 overview</div>
<div id="section3">Section 3 overview</div>
<div id="section4">Section 4 overview</div>
I want to display the div marked 'General overview' by default, and to hide all of the other divs (section1, section2, section3 and section4) but would like to swap out the 'general' div with the other divs as the corresponding links are moused over.
e.g. mousing over the Section 2 link will replace the 'general' div with the 'section2' div. On mousing out, it will revert back to the 'general' div. Mousing over the Section 4 link will replace the 'general' div with the 'section4' div. On mousing out, it will revert back to the 'general' div. Etc etc....
View 11 Replies
View Related
Jul 12, 2009
From my understanding the main feature of unobtrusive JavaScript is to remove event handing from the markup.The main reason for doing this is to avoid repetition of code.There are also other reasons but that is the main one. e.g. no having to write <tag onclick="function()" > over and over again. This traditional event handling method makes code less maintainable.However is it worth writing unobtrusive code when we consider the following:
1, Server sider scripting laguages can be used to avoid code repetition. e.g. we can use a loop to add multiple onclick event handlers to all the elements of a navigation list. Thus we would only have to write onclick="function()" once.
2, Unobtrusive coding makes the code harder to follow.It is easier to look at the markup to find out what happens when an event occurs on an element rather than having to look through wades of JS code to find the correct event listener. This is especially true when a team is working on a project. It is easier to find out what another person has done when the traditional model of event handling is used.
3, Unobtrusive coding means longer and more complicated code. Also there there is a need for having to deal with browser differences.I know this can be reduced using libraries such as JQuery. Is it worth using such a library?
View 2 Replies
View Related
Nov 16, 2009
Does anyone know how to make the cycle function in jquery unobtrusive?
I've got the following code and when I disable javascript, I get a nasty long list of images :(
Jquery code:
Html code:
View 1 Replies
View Related
Mar 19, 2011
without outside extensions (http://remi.org/2009/01/06/using-firebug-to-debug-unobtrusive-javascript), how does one debug javascript events on a webpage that primarily relies on unobtrusive JS events? for instance, i have a website i log into that has a "submit" button. the button itself only has this code:
<input type="image" class="png" tabindex="5" value="Go" src="login.png">
obviously, the only way that it can submit the form is to use javascript. and it's obviously unobtrusive in this case.consider the fact that it isn't my webpage, and i don't want to try to put random breakpoints everywhere blindly.
View 4 Replies
View Related
Aug 9, 2005
I have an old web application I did where browsers with dynamic
capabilities received a drop down menu on the top of the page and a
fold out on the left hand side of the page and non-dynamic browsers
received two static menus. This was done via server side detection of
browser capabilities and branching the application. Over time needless
to say the capabilities between the dynamic and static sides got
seriously out of whack.
Now the drop-down menu was not done unobtrusively, it was done via
mouseovers and the like.
Obviously it makes sense to change the menus to be done by catching
events. But I would also like to redo the dynamic and static branching.
The way I figured would be as follows:
The static menus are placed inside of noscript elements.
The dynamic menus are loaded with display set to none. Script writes in
a new css changing dynamic menu display to block.
As I understand noscript is considered bad via unobtrusive javascript
theory, however I have a hard time seeing how one could make a menu
that would display properly as a static menu yet also function as a
drop down or fold out (especially fold out), collapsible expandable
menus are easy since they basically have the menu order placed in the
structure needed.
So I'm wondering if anyone has reasonable suggestions on how to
succeed.
On another subject, anyone know what the effect of a bunch of links
inside a noscript element that mirror a bunch of links in the normal
page will do to Google's algorithms?
View 2 Replies
View Related
Nov 3, 2010
I am trying to create a basic unobtrusive form validation function but I am having some issues/questions. Basically I am checking if any of the form fields have <= 3 characters, and if they do so, then I make those fields' backgrounds and borders red. Also in the empty <span> tags I insert an error message. My issues/questions are:
#1: So when I say if (fieldVals<=3) this means that the errors should appear if the values are 1,2 or 3 characters long, right? It does not do that though, when I insert one character in any of the form fields the errors go away, but they should not, right?
#2: How do I cancel the form from submitting if errors are visible and vice versa? When I use the return false when errors are visible, the code does not even run. What is going on? return true does the same.
#3: When I use a submit button(type="submit") instead of just a button(type="button"), the code does not run? What am I doing wrong?
I am not trying to use this on a website, I am just trying to learn how to use unobtrusive javascript. That's why I am only checking for empty fields. If I learn how to do this first, later I will try to add email check, date check etc.
THE CODE:
View 12 Replies
View Related
Oct 10, 2011
I have a simple button in my HTML. I also have a function in my external JavaScript file. This function calls an alert box with some text. Now, I also have a global variable in my JavaScript that gets the button by id, then assigns the onclick event handler to it which in turn is assigned the call to my alert box function. Simple right?
Problem: The alert box shows up when the page loads as well as when the button is clicked. This is not desirable. code...
View 14 Replies
View Related
Jul 23, 2005
I have a problem with the following function:
I would like to define the hight/length of the window which I open when
I call the function.
The problem is that the window opens but not with the size I defined
when calling the function. Code:
View 5 Replies
View Related
Jul 23, 2005
Can someone give me some pointers on how I can read one or more
arguements from a url, using js?
Why? I'm working on a LAMP based project and when a user successfully
registers, the header redirects to the login screen - I'd like to check
for the value of register, if read from:
http://www.mydomain.com/index.html?register=success
A pointer/hint as opposed to a solution should be sufficient because I'm
doing pretty well learning javascript.
View 1 Replies
View Related
Oct 6, 2005
I am pretty rusty with javascript and I am trying to make a webpage
that will basically act as a wrapper from one webpage to another. What
I mean by this is that I will hit this page like:
webpage.htm?Param1=... and I will take the passed params and post them
to another page. I have the post part working, but I was just
wondering how I can use just Javascript and read those values passed to
this webpage. Is this even possible?
View 3 Replies
View Related
Jun 2, 2007
I found this little script for extracting parameters from a url but wondered
what the shortest and most efficient way to do it would be, like the
following or via regexp?
function getParameter(paramName) {
var currentUrl = window.location.search
var strBegin = currentUrl.indexOf(paramName) + (paramName.length+1)
var strEnd = currentUrl.indexOf("&",strBegin)
if (strEnd==-1)
strEnd = currentUrl.length
return currentUrl.substring(strBegin,strEnd)
}
Any shorter way?
View 1 Replies
View Related
Jul 20, 2005
I have an onclick function that pops a new window (nothing fancy) the problem is that whenever I want to return to the page where I popped the new window from I find that it is reloaded and has taken me to the fist line of the page. What parameter (or anything else for that matter) can I add in order to pop up a new window and still be in the same place when I return to the previous page?
View 2 Replies
View Related
Apr 21, 2011
I need to know a way to get/set URL parameters with jQuery.
Here is the flow between pages im having:
What i want to have is:
Each page offers a choice to user and must add the choice in url. Actually im using forms with submit buttons to do it but i dont know how to keep parameters from previous page in the current page.
View 6 Replies
View Related
Jun 7, 2009
I need to get which all are the parameter in the current url[URL]...Since my parameters changes every time, I need to get the parameters (not values of parameters)
[Code]...
View 1 Replies
View Related
Oct 17, 2009
It's possible to get values from URL with jQuery like PHP? For example suppose you have this URL:form.html?s=ok&val=rperezm. In PHP is simple:
[Code]..
View 3 Replies
View Related
Jan 20, 2010
I want to pass parameters thru URL. I know how to pass. I am finding problem in reading the parameters. here is the [URL]. how to to read these parameters from URL using java script?
View 3 Replies
View Related
Feb 1, 2011
i m trying to implement captcha in my site.i m using recaptcha. To check the captcha i need to request url like: [URL] and then i need to check response from url if it is true or false i dont know how to request response from url
View 2 Replies
View Related
Jun 6, 2011
I am making a function that executes code as AJAX readyState's are returned. If readyState = 3 then I running code through eval but I want to be able to run functions with parameters, within the parameter that is evetually executed by the eval
Heres abit of pseudo code of what I am talking about
function receiveRequest(whileLoading, whenDone) {
// AJAX stuff... blah... blah... blah...
if request is being processed:
eval(whileLoading)
if request is done:
eval(whenDone)
[Code]...
I haven't used Javascript in agggeeesss and I can barely remember anything anymore - PHP <3
View 2 Replies
View Related
Apr 26, 2011
In the javaScript function below, is there anything I can add to the window.open so that the parameters passed in the URL do NOT show in the window that is opened? It is okay if the script path shows, I just need to hide the parameters. If that is not possible, can I have it show no URL show at all?
function OpenTest2(ID,course,test)
{
var agree=confirm("Are you sure you want to Launch this test?");
if (agree){
path = "testing_center/frameset.cfm?TestID=" + ID + "&UserID=<CFOUTPUT>#session.userID#</CFOUTPUT>";
window.open(path ,'popuppage','scrollbars=yes,fullscreen=yes');
[Code]...
View 4 Replies
View Related
Jul 12, 2007
Is there a way to send parameters to the function being added to an event with addEventListener. I.E. say you have this function
Code:
function someFcn(i){
alert(i);
}
and I add it to an object.
Code:
someElement.addEventListener('focus', someFcn, false);
Is there a way to send a parameter to someFcn.
For Example I have tried this but it failed
Code:
var someString = 'Hello World'
someElement.addEventListener('focus', someFcn(someString), false);
View 3 Replies
View Related