if ($amLanguage['id'] == AM_DEFAULT_LANGUAGE_ID){
?>
<input id="default_language" type="image" src="<?php echo DIR_WS_CATALOG_LANGUAGES . $amLanguage['directory'] . '/images/' . $amLanguage['image'];?>" title="<?php echo AM_AJAX_CHANGES;?>"
<?php echo 'onclick="return amSetInterfaceLanguage(\''.AM_DEFAULT_LANGUAGE_ID.'\');"';?> >
<?php
}else{....
And I have:
$(document).ready(function() {
function language_def() {
$('type#default_language').trigger('click');
}
});
The purpose is to trigger the click event, simulating a users click, for the id="default_language"
I have been trying for days, but nothin works...:(
Somebody plz
Sara
You put the trigger code in a function. Either call it or Remove the function.
$(document).ready(function(){
$('#myObject').click()
});
Also, everything before the # id selector is irrelevant and just wastes bits.
This won't work?
$(document).ready(function() {
function language_def() {
$('type#default_language').click();
}
});
Actually, why do you need the function language_def? Simply doing this may work:
$(document).ready(function() {
$('type#default_language').click();
});
Related
I'm making a forum and I want the user panel to change whenever a user is logged in. So by default it says "Sign in or register." But when a user is logged in it says their name and an option to log out.
The idea is that when they click sign out jQuery will ask for a confirm and if its true they will be redirected to ?logout=true where php handles the rest.
The problem is that jQuery just won't work on the element echoed by php.
Here is the PHP:
<div id="userbar">
<span id="userPanel">User Panel</span>
<?php
if (isset($_SESSION['signedIn'])) {
echo '
Sign Out
<span id="welcome">
Hello, <b><a href="#" class="sessName">' . $_SESSION["username"] . '
</b></a></span>
';
} else {
echo '
Sign In
Register
';
}
?>
</div>
And here is the jQuery:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(".logout").click(function(){
var exit = confirm("Are you sure you would like to sing out?");
if (exit == true) {
window.location("header.php?logout=true");
}
return false;
});
</script>
First, you need to update your jquery is too old.
this the final function i create, you can try it.
function alertLogOut(){
var exit = confirm("Are you sure you would like to sing out?");
if (exit == true) {
window.location.href="header.php?logout=true";
}
return false;
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
Sign Out
You may add your listener on the top of your html. Try to make it this way :
$(document).ready(function() {
$(".logout").click(function(){
var exit = confirm("Are you sure you would like to sing out?");
if (exit == true) {
window.location("header.php?logout=true");
}
return false;
});
});
This way, jQuery waits until your DOM is completely loaded.
As the element is not already created in the DOM, you need to use a delegated event for it to work.
See Understanding delegated events
So you would do like that, but you can attach to another container if you wish :
$(document).on('click', '.logout',
function() {
// Do your things
})
EDIT : I misleaded, everything is already in the DOM with PHP echo
Hey guys I have this populated search form that will bring a table of people based on search result. I need to be able to get the php variable that has the username I am trying to get, then that will get sent over to .php file using the JQuery UI which will open a notes window.
So here:
username, other, other , notes - this is a link and once clicked the following is called:
$(document).ready(function () {
$("#NotesAccessor").click(function () {
alert(notes_name);
run();
});
});
which leads to :
function run(){
var url = '/pcg/popups/grabnotes.php';
showUrlInDialog(url);
}
to a function that opens the Jquery Dialog.
I need to access the username of the based notes that was clicked....if there was 20 results of different names, david, joe, john, etc... I click the notes with david as username, I need that to be sent over to the file that is opening so I can display the based notes on the appropriate username.
Here is my php:
.........
<td>
$csvusername
</td>
.........
<td>
";
if ($checkNotes[1] == 'No')
{
echo "None";
}
if ($checkNotes[1] == 'Yes')
{
echo "<a href='#' id='NotesAccessor'>Click to access</a>";
}
echo "
</td>
........
Let me know if this makes sense to you. I am kinda stuck on this and could use a hand :)
David
I can't tell what PHP variable you are trying to get, but generally, you can do:
<!-- /myScript.php?myVar=helloWorld -->
<script type="text/javascript">
$(document).ready(function(){
var myPhpVar = <?php echo $_GET['myVar']; ?>;
alert(myPhpVar);
});
</script>
<script>
var x = '<?php echo $variable; ?>';
or
var x = '<?php echo my_function(); ?>';
</script>
<?php
function my_function()
{
return $variable;
}
?>
this should do what you like :)
if $list[$i][wo_status] has no value,
I call whatson_read function,
it do ajax for db operation.
after success url reokaced
screen location moves to location of element id specified.
but after few micro second, secreen moves to top location.
why this happens?
php section
if ($list[$i][wo_status])
echo "<a href='" . $list[$i][url] . "' $target_link >";
else
echo "<a href='#' onclick='javascript:whatson_read(\"" . $list[$i][url] . "\", " . $list[$i][wo_id] . "); return false' >";
Javascript section
<script type="text/javascript">
function whatson_read(url, wo_id) {
var post_url = "<?=$g4[bbs_path]?>/ajax_whatson.php?w=r&wo_id="+wo_id;
var data = "";
$.ajax({
type:"POST",
url:post_url,
data:data,
async:false,
error:function() {
alert('fail');
},
success: function(){
<? if ($target) { ?>
parent.<?=$target?>.location.href = url ;
<? } else { ?>
location.href = url;
<? } ?>
}
});
}
</script>
Please don't use <a href="javascript:">. That's an old, outdated practice.
Currently, your link is pointing to the in-page anchor #. That anchor doesn't exist on the page, so when you click the link, the browser just takes you to the top of the page.
You need to return false from your onclick handler to prevent the default action of the click event. This is conventional in JavaScript:
<a href="#" onclick="whatson_read(...); return false;">
Your problem is most likely in the else section of your PHP.
Replace href='#' with href='javascript: void(0)'
Use javascript:; rather than putting # in href attribute of <a> tag.
Also while binding function to links you can make that function return false, so that event is no further propagated. Event propagation makes the browser goto top of page.
Also there is no requirement to have javascript: text in your onclick event. Html Onclick event can directly accept javascript code.
thanks for everyone.
I found your suggesstions are good for my program,
and my issue is due to IE bugs related anchor.
but, issue was not resolved.
http://www.webmasterworld.com/html/3322666.htm
I changed
<a name="c_<?=$comment_id?>"></a>
to
<a name="c_<?=$comment_id?>" id="c_<?=$comment_id?>"></a>
I am writing some jquery to call an ajax script every 2 seconds to get the result and update the page. I am mostly a backend programmer and could use some help on this.
This is the code I have now:
<script language="javascript">
function downloadProgress(id) {
$("#" + id + "").load("index.php?_controller=download&_action=getDownloadProgressAjax",
{
downloadId: id
}
);
setTimeout(downloadProgress(id), 2000);
}
</script>
<?php
foreach ($downloads as $dl) {
?>
<div id="<?php echo $dl["download_id"]; ?>">
<script language="javascript">
downloadProgress(<?php echo $dl["download_id"]; ?>);
</script>
</div>
<?php
}
?>
This does not work. What am I doing wrong or would you suggest another approach?
Thanks
I think that you are confusing your PHP script by giving it both query string variables (sent as GET) and data (which is probably getting sent as POST). Try this:
$("#" + id).load("index.php?_controller=download&_action=getDownloadProgressAjax&downloadId="+id }
since you are using jquery, you can use the $.ajax function when the page is ready.
$(function () {
function function downloadProgress(id) {
$.ajax({
url: "index.php?_controller=download&_action=getDownloadProgressAjax&downloadId="+id
})
setTimeout(function () {
if (downloadnotcomplete){ // this way your script stops at some pont.
downloadProgress(id);
}
},2000);
}
});
You will attach the downloadProgress(id) function to your download button or anything else, to trigger the function the first time.
The problem you are having is that you have to provide a parameterless function and not a function call to setTimeout. Also, I would do it a little bit different and use setInterval instead of setTimeout as it relays your intention better in the code. Here is how I would do it:
<script language="javascript">
$(function() {
setInterval(downloadHandler, 2000);
});
function downloadHandler() {
// I'm not sure where the id is coming from you will probably need to put a
// class on your div's so that you can select them.
$(".MyDivClass").each(function() {
var id = $(this).attr("id");
downloadProgress(id);
});
}
function downloadProgress(id) {
$("#" + id + "").load(
"index.php?_controller=download&_action=getDownloadProgressAjax",
{ downloadId: id }
);
</script>
and then on your div:
<?php
foreach ($downloads as $dl) {
?>
<div id="<?php echo $dl["download_id"]; ?>" class="MyDivClass"/>
<?php
}
?>
Hope this helps.
i have tried:
<?php include("delete.php") ?>
<?php
....
....
....
if($result=mysql_query($sql))
{
echo "<table><th>Id</th><th>Name</th><th>Description</th><th>Unit Price</th>";
while($row = mysql_fetch_array($result))
{
echo "<tr><td>".$row['Id']."</td><td>".$row['Name']."</td><td>".$row['Description']."</td><td>".$row['UnitPrice']."</td>
<td><a href='delproduct($row[Id])' onclick = 'return MsgOkCancel()'>Delete</a></td></tr>";
echo "<br/>";
}
}
?>
following javascript is in the same page:
<script type="text/javascript" language="javascript">
function MsgOkCancel() {
if (confirm("Are You Sure You Want to Delete?"))
{ return true }
else
{return false}
}
</script>
where delproduct is a javascript function in delete.php
written like:
<script type="javascript">
function delproduct(Id)
{
alert('Id '+ Id);
}
<script>
** after ** clicking Delete a okcancel message-box appear asking conformation
** but ** after clicking 'ok' it should execute statements inside delproduct function but it doesn't
it gives error like:
Object Not Found :The requested URL was not found on this server.
what would be the problem?
pls help,
thanks
A URI without a scheme (such as http:) is treated as a relative URI.
You appear to be looking for javascript: (which should never be used for anything other than creating bookmarklets).
What you should be doing is something along the lines of:
onclick="if (MsgOkCancel()) { delproduct($row[Id]); return false; } else { return false; }"
However, you should have something that works in the href, but since this appears to be making a significant change on the server, you should be using POST not GET, so a link is the wrong tool.
What you probably should have is:
<form action="/delete" method="post" onsubmit="return delete(this);">
<input type="hidden" name="id" value="<?php echo htmlspecialchars($row[Id]); ?>">
<input type="submit" value="Delete">
</form>
Combined with:
function delete(form) {
if (confirm("Are You Sure You Want to Delete?")) {
delproduct(form.elements.id.value);
}
return false;
}
Better yet, get rid of the onsubmit attribute and assign the event using JavaScript.
I think you need a different setup.
First of all, if you are going to call javascript functions in an href attribute, you need to prepend it with javascript: like so href="javascript:delproduct(...)". But calling javascript from an href attribute is not recommended. That attribute is intended for urls.
I would advice you to create a function that displays the messagebox and based on the action of the user, calls the delproduct function. Something like:
function confirmDelProduct( id )
{
if( msgOkCancel() )
{
delproduct( id );
}
// return false is meant to stop the href url from being called
return false;
}
And in your html:
<a href="#" onclick="return confirmDelProduct(' . $row[ 'id' ] . ')"> ... etc
What about this one:
PHP:
<a href="javascript:void(0);" onclick=\"delproduct({$row[Id]})\">
JS:
function delproduct(Id){
if(MsgOkCancel()) alert('Id '+ Id);
}