Changing Variable Value With OnClick?
Nov 13, 2011
I am building a site where I want all links to partial page reload using xmlhttprequest and innerhtml. I have done this before, butI always had to have a seperate xmlhttprequest function for each link. So this time I am trying to write just one function, and have the onClick change which document the request is getting. It is not working and I appear to novice to figure out why. Here is the code, i have bolded some relevant lines:
<script type="text/javascript">
function ChangeContent()
{
var whichPHP;
[Code]....
Also, if I use the innerhtml function to write another of these hrefs, will that link be able to access the function if it is in the header, or should I put the entire function in a .js file on the server? The point of all this would be that the entire page never reloads and all the text content is swapped out on demand.
View 3 Replies
ADVERTISEMENT
May 28, 2007
i'm not really sure how to explain this, since I know nothing about javascript, so i'll try and illustrate by the use of php (hope it makes sence)
I have a set of different links, like:
<a href="link.com?page=text1">text 1</a>
<a href="link.com?page=text2">text 2</a>
<a href="link.com?page=text3">text 3</a>
etc, where page is dynamic and can be anything I chose..
Another place in the same document, I echo out what the page variable is, like:
echo "$page";
so when clicking "text 1" the echo will output what i've defined the page to be, in this case "text1" ..
So I want to be able to click the links and change the output of the echo all depending on what i've defined in the link - without refreshing the page!
Is there any easy way to do this?
View 2 Replies
View Related
Oct 16, 2009
I'm trying to create an array of dates two weeks apart from an arbitrary startDate, and I've noticed some odd behavior in my variables. I did a little experiment on my JS console and here's what I got. My inputs are in blue, the output is in black.
Code:
Everything's good so far, but here's where it gets odd. I try to add 14 days to cur.
Code:
Why is it that when I make changes to cur, the same changes are made to startDate?
View 7 Replies
View Related
Jul 29, 2010
I have a div called pageWrap to wrap my page with the css as margin-top:-46px;
I would like to use Javascript onClick on another div. This Div is called loginButton, the onclick should change the the css of pageWrap to 0px and onclick again should change it back.
View 2 Replies
View Related
Aug 31, 2011
Here is my script -- Applied in <head>
<script language="JavaScript">
var bgImage = new Array(); // don't change this
bgImage[0] = "images/aboutus_1.jpg";
[code]....
this goes on, however, it does not change the background when clicking on "Welcome" or "About us" Links. Where I want "About us" to load image#0 in the index and "Welcome" to load image #1.
View 1 Replies
View Related
Jul 16, 2006
I'm using a simple script that moves a DIV from one location to another when the user mouses over it. The problem is, I want the user to have to click the div for it to move and then click it agin to move it back. I've been trying to find a simple solution without luck. Code:
View 2 Replies
View Related
Mar 28, 2002
I think this board would be the best as it does hopefully end with an onclick element...
OK, I have a table, where I have ID'd the headers as such:
<table>
<col id="col1"><col id="col2"><col id="3">
<tr>
<td>Some Text</td>
<td>More Text</td>
<td>More Text</td>
<tr>
</table>
Now, when I click on the header row, I would like to hide a column, and when I click on an image, I'd like to restore it. Ideally, I would have a function like such:
function set_state(item, state)
{
if (state == 1)
{
item.css.visibility="collapsed";
}
elseif (state == 2)
{
item.css.visibility="hidden";
}
else
{
item.css.visibility="visible";
}}
However, I don't know how to pass the item along. Like telling it to hide col2, etc, etc.
View 2 Replies
View Related
Mar 18, 2010
I've set up a few images to change onlick using the following code (I have the alternate images saved as jpgs in the img/ directory). There are two problems I'm having the first baffles me, after clicking one image and changing it the other images take 2 clicks before changing. The other problem is more of a curiosity, I plan to have these images work as a sort of check box for a sql database query and I'm not entirely sure my current way of doing it will allow for that.
Code:
<body>
<head>
<script language="JavaScript" type="text/JavaScript">
var q=0;
[Code]....
View 2 Replies
View Related
Aug 2, 2011
I am trying to create a button that when pressed changes not only the value of the button but the onclick event. I basically need the function to toggle between these two functions but I can't get it to work. The button changes value but will not update with the new onclick value.
HTML Code:
<html>
<head>
<script type="text/javascript">
[code]....
View 1 Replies
View Related
Apr 18, 2007
The following is a very simple example of what I want to do take an
elements oncontextmenu and changing it dynamically onclick of that
same element. The code below will fail unless you change the line
document.getElementById('div1').setAttribute('onco ntextmenu',
someText);
to
document.getElementById('div1').setAttribute('onco ntextmenu',
function(){alert('World World');return false;});
............
View 3 Replies
View Related
Jun 10, 2010
I hope that someone can help me with this strange problem I have here. I have some script which changes a button and changes the onclick event. The strange thing is that although it is changing it. All the events have the same parameter even though my code is giving each button's onclick event it's own unique parameter.
[Code]...
View 1 Replies
View Related
Mar 6, 2010
I have an image set to the background, this method is working for fire fox, here is how i got a background image.
<img src="docs/Plasma.gif" id="background"/>
<div id="content">
Right after the body tag and
img#background { position:fixed;
top:0;
[Code]...
When someone clicks on these thumbnails it changes the backround image's source to the bigger version. It doesn't work in IE though and i am confused why. I have tried preloading the image, but I feel as though my Javascript is being ignored.
View 2 Replies
View Related
Jun 6, 2011
I would like to change the value of a single hidden input onclick. The possible values are text, email and URL.I've tried all kinds of "ways" (inline and in function in a variety of ways,) but nothing. I stripped it down one last time to give it another go, but realize I'm out of ideas, so the code below is simply where I've thrown in the towel.Can someone make this work with a JS function, so that each link may be clicked and change the hidden input's value to the respective value?
View 3 Replies
View Related
Sep 27, 2006
I have the following code:
<script language="JavaScript">
function func1() {
alert("func1 invoked");
}
function func2() {
alert("func2 invoked");
}
function changeFunction() {
var img = document.getElementById('img');
if (window.addEventListener) { // Mozilla, Netscape, Firefox
img.addEventListener('click', func2, false);
}
else {// IE
img.attachEvent('onClick', func2);
}
}
</script>
<img id="img" src="test.jpg" width="10" height="10" onClick="func1();"></img>
when the image is clicked with the mouse, function func1 is invoked as expected. When I call function changeFunction, I want to change the code that is invoked when the image is clicked from func1 to func2. Instead, both are invoked because addEventListener and attachEvent add an additional handler instead of setting one.
I am looking for a way to change the handler from one function to another. Can anyone think of a solution probably using removeEventListener?
View 2 Replies
View Related
Jan 3, 2010
HTML Code:
<ul id="toggle">
<li class="previous"><a id="prev" href="#cat">previous</a></li>
<li class="next"><a id="next" href="#dog">next</a></li>
</ul>
I'm trying to force previous to be hidden until next is clicked and when next is clicked the link will change from #dog to #sheep.
Does anyone know an article or something on this?
View 21 Replies
View Related
Nov 15, 2010
I have a button that needs to increase/decrease the value of a text field when clicked. This code is working in Internet Explorer and Chrome, but not Firefox.
Code:
<a onClick="scorebox1 = parseFloat(score1.value); score1.value = scorebox1 - myscore; scorebox1 -= myscore;"><img src="images/minus.png" alt="Subtract Point" border="0" /></a>
<input size="2" name="score1" style="font-size:24px; width:50px; text-align:center; color:#FF0000;" id="score1" value="0" />
[Code]....
View 4 Replies
View Related
Aug 10, 2011
I am trying to stop a preloaded images used in a rollover. The images are linked to a tab navigation system, that open on the same page.
if(document.images){
var image_array = new Array();
// path to the directory with images
var path = './images/food-drink/food/';
// enumeration of the "active" images
[Code]....
View 1 Replies
View Related
May 21, 2011
Im trying to merge the functions of two buttons In this script
<script language="JavaScript">
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
[code]....
View 3 Replies
View Related
Dec 23, 2010
I have a textbox thats initial text color is set to grey, I want to change the text color to black when the user clicks on it, is this done by using onclick="style=color:Black;" I have tried this and failed but maybe ive got something slightly wrong or is it done a different way completely.
View 7 Replies
View Related
Jan 16, 2011
My problem is i do not know the syntax for changing the button image when on click meaning when i click on a imagefield button it will change to another imagefield button and when i click again it will change back.I know that we have to create a function something like this?I am not sure of the syntax but will learn from you expertX - what to put in here?
function changeImage()
X
end function
[code]....
View 2 Replies
View Related
May 11, 2010
I found a function online that allows me to swap text onclick and have amended it as follows:
Code:
function swapText(obj, n) {
if(obj.oldText){
obj.innerHTML = obj.oldText;
obj.oldText = null;
[Code]...
I have this partially achieved when clicked, any number will indeed "turn into" an h1'd representation of itself but I can't get the other links in the group to disappear when the h1'd number appears (onclick).
View 17 Replies
View Related
Jul 19, 2010
I need to find a way to change a php variable with javascript.
lets say in php
PHP Code:
$a = '1';
I have a set of buttons (1) (2) I click (2), the onclick some how changes $a to '2'.
Is there a method for this?
View 4 Replies
View Related
Jun 6, 2009
I'm working on an ordering form which calculates the total order price using Javascript. I have a checkbox which I want to use to toggle the display of various items, and also reset the value of an item depending on whether or not it is checked.
Further details
I have a checkbox for the colour "Black" which, when checked, hides a SELECT, a bit of text, and "Quantity" field. It also resets the value of the "Quantity" field to zero.
When the "Black" checkbox is unchecked, the three items (SELECT, text and Quantity) are revealed again, and the Quantity field for "Black" is reset to zero and hidden.
The reason is that users can only either EITHER a black item or select from a list of colours. Black items are a different price to all others.
How the form works
When the user enters a quantity into a text field for each item, the price of that item is added to the total at the bottom of the form. When the form is submitted (with PHP validation), it emails the order to a salesperson. The price of each item (for emailing the order) is set using hidden form fields with defined values, while the order total is calculated using the id of each quantity field (e.g. "item_31_85.00").
What I need to know
I want to achieve the following when the "Black" checkbox is clicked:
Toggle the display of three items (SELECT field, text (in a DIV) and an INPUT)
Reset the value of the INPUT field (and reset a different INPUT when the checkbox is clicked again)
My current code
The code I'm currently using in the PHP form is below (truncated for readability):
Code:
<input type="checkbox" name="black" onclick="togglecontent('colour_box','colour_price','color_quantity','quantity_reset')" /> Black
[Code].....
Currently I can hide the SELECT and accompanying text when I check the "Black" checkbox, but it won't reset the INPUT value nor hide it. I've not yet attempted to do unhide and hide the Black text and input since I can't get this part working yet.
View 14 Replies
View Related
Nov 18, 2009
Ok, 'nother head-banger for the hardcore!
I have a "contact us" <a> with the id 'contact' on the main page, which is supposed to change the source file of an iframe to the contact page. Except when I click on "contact us" nothing happens.
I've tried to get this to work several different ways, and suspect that the problem is purely syntax, but I just haven't been able to figure it out.
Here's the code:
The snippet on the main page (index.html):
<div id="linkListContact" class="LinkList">
<img id="linkListContactBg" class="SideBarBgImg" src="Assets/Backgrounds/SideBar/ContactBg.png"></img>
<span>
[Code]....
The setIFrame function is used to call the content initially when the page loads, and is working beautifully in that context. You can see the problem in action at the actual site: [URL]
View 3 Replies
View Related
Jun 23, 2011
My code is pretty simple:
var runUpdate = true;
$.get("FirmMaintServlet?action=checkfirmid&firm_id="+$('#new_firm_id).val(), function(data) {
if(data) {
[Code]......
When this runs, if the first alert shows it is supposed to set runUpdate to false, as you can see. But when the second alert shows it is still equal to true.
View 6 Replies
View Related
Oct 2, 2010
I have two pages. In one page I am changing the value of a variable called t, in the other I am outputting it. The problem I'm having is in changing its value.
[Code]....
View 1 Replies
View Related