Ok, I can't find an example but I can provide you with the main idea.
function myButton () {
Ajax code here..
}
<script>
jQuery code..
</script>
-----
// After HTML opening you can do a button like
<button id="button-to-work-on" onclick="myButton()" >Press me</button>
This way you can easily do the ajax and jquery.
Please "Marks As Answer" if any answer helped you out!
~~! FIREWALL !~~
<scripttype="text/javascript"> function
buttonHandler() { $("#close").remove(); } </script>
And in the partial view I have this:
<br/> <buttonid="close"onclick="buttonHandler">Click
to Close</button>
Of
course when I click on the button that is in the Partial View.... NOTHING HAPPENS :-(
What
am I doing wrong with this?
Oh,
BTW, you didn't expain how to call jquery code from JavaScript, and that's why I ended up putting the jqurey code in the JavaScript code in the first place... just in case you were wondering....
Actually It is working on the public faceing page just fine,
And on the private Admin page it works too.
But on the private BackOffice page it only removes the button with an id="close";
This is the function that I'm using:
<scripttype="text/javascript"> function
buttonHandler() { $("#onlineUsers").hide(); } </script>
The only issue I have with it, other than removing only the button in one case, is that to get it working again the page needs to be refreshed. If there is a way to do this without having to refresh the page or by refreshing the page without the user having to
do anything that would be what I'm looking for.
I did put the alert property were it should have been because it worked in the public facing _Layout.cshtml file and then I copied it to the two other _Layout.cshtml files!
The issue is that authenticated users for some strange reason don't get the click value on the button.
I'm not a JavaScript develper so I don't know any more than I find on web sites.
What I think I need to do is add a onclick="something" in the <input ... > button but I don't have a clue as to what that "something" should be!
This is what I have currently and it's still not working:
<scripttype="text/javascript"> function
buttonClick() { $("onlineUsers").toggle(); alert( "button clicked"
); } </script>
And this is the button:
<inputtype="button"id="button"onclick="buttonClick"value="Toggle"/>
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 01, 2013 11:17 AM|LINK
I'm smart enough to take an example and modify it for my purposes.
I'm not quite smart enough to do much without an example.
That's why I asked for a sample <div> close jqurey code that is assigned to a button.
It is the part of assinging jquery to the button that I'm stumped on!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 01, 2013 04:43 PM|LINK
Ok, I can't find an example but I can provide you with the main idea.
function myButton () { Ajax code here.. } <script> jQuery code.. </script> ----- // After HTML opening you can do a button like <button id="button-to-work-on" onclick="myButton()" >Press me</button>This way you can easily do the ajax and jquery.
~~! FIREWALL !~~
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 01, 2013 07:33 PM|LINK
Okay, I have this in the _Layout.cshtml file:
<script type="text/javascript">
function buttonHandler() {
$("#close").remove();
}
</script>
And in the partial view I have this:
<br />
<button id="close" onclick="buttonHandler">Click to Close</button>
Of course when I click on the button that is in the Partial View.... NOTHING HAPPENS :-(
What am I doing wrong with this?
Oh, BTW, you didn't expain how to call jquery code from JavaScript, and that's why I ended up putting the jqurey code in the JavaScript code in the first place... just in case you were wondering....
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 02, 2013 12:58 PM|LINK
http://www.w3schools.com/jquery/jquery_dom_remove.asp According to this, remove only removes the content. Not hides it.
And Ajax is not there in your code.
Also the javascript usage is somehow not a good one just use it as
<script> $(document).ready(function () { $("#button-hide").click(function () { $("#button-to-be-hidden").hide(); )} )} </script>This could be the jQuery.
Than the ajax code in your file.
http://www.w3schools.com/jquery/jquery_ref_ajax.asp This link will provide you with the basics elements of using jQuery with Ajax
~~! FIREWALL !~~
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 02, 2013 01:25 PM|LINK
Actually It is working on the public faceing page just fine,
And on the private Admin page it works too.
But on the private BackOffice page it only removes the button with an id="close";
This is the function that I'm using:
<script type="text/javascript">
function buttonHandler() {
$("#onlineUsers").hide();
}
</script>
The only issue I have with it, other than removing only the button in one case, is that to get it working again the page needs to be refreshed. If there is a way to do this without having to refresh the page or by refreshing the page without the user having to do anything that would be what I'm looking for.
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 02, 2013 01:56 PM|LINK
After looking at your recommended site, I decided to try their method of doing things:
<script type="text/javascript">
@(document).ready(function() {
$("button").click(function() {
$("onlineUsers").toggle();
})
})
</script>
This function is located in the <head> section of the file. But when I run it, I get a runtime error saying:
Compiler Error Message: CS0103: The name 'document' does not exist in the current context
Question: What do I need to do to clear this issue???
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 02, 2013 03:22 PM|LINK
I put an: alert( "button clicked" ); into the JavaScript function and when I clicked the button I did not get the alert.
This tells me that the button click event never fired. Of course I'm clueless as to why this is the case.
Any other suggestion?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
Afzaal.Ahmad...
Contributor
2661 Points
1040 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 04, 2013 08:02 AM|LINK
That is because you might not have set the alert property to the one it should have! Please try having a look at alert property first.
http://www.w3schools.com/js/js_functions.asp
~~! FIREWALL !~~
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 04, 2013 12:53 PM|LINK
I did put the alert property were it should have been because it worked in the public facing _Layout.cshtml file and then I copied it to the two other _Layout.cshtml files!
The issue is that authenticated users for some strange reason don't get the click value on the button.
I'm not a JavaScript develper so I don't know any more than I find on web sites.
What I think I need to do is add a onclick="something" in the <input ... > button but I don't have a clue as to what that "something" should be!
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.
eric2820
Contributor
2777 Points
1161 Posts
Re: Looking for JavaScript code to close an AJAX display
Jan 04, 2013 01:06 PM|LINK
This is what I have currently and it's still not working:
<script type="text/javascript">
function buttonClick() {
$("onlineUsers").toggle();
alert( "button clicked" );
}
</script>
And this is the button:
<input type="button" id="button" onclick="buttonClick" value="Toggle" />
Quetion: What could I be doing wrong?
http://www.my-msi.net/Admin
blog
If a post helps you, please mark it as Ansered, thank-you.