Prevent colon in URL from changing to %3A - html

Is it possible to have a colon from a form go into a link to populate a form on a new page? At the moment the link keeps changing to %3A.
For example, current: http://www.test.com/?field=123%3A456
Trying to have: current: http://www.test.com/?field=123:456

You can't.
You need to decode the parameters
for serverside php you can use
http://php.net/manual/en/function.urldecode.php
$field = urldecode($_GET['field'])
for javascript you can use
decodeURIComponent('123%3A456');

Related

using href or routerlink with #

I'm fairly new to changing paths / position of page so I would like a little help on this.
Say, when a button is clicked, I want to scroll down to another portion of the page. (where id of that section is 'xyz') however, I'm using an entirely different component to access that section.
If I were to use href, I can easily do : href="/app/appid#xyz"
however, if appid is a variable retrieved from the ts file, how can I insert it into my href?
It's easier to to use [routerlink]="['app', appid]" but how can I insert the "#xyz" into my string?
Or is there a completely separate and easier functionality I can use?
Thank you
Add the frament attribute:
<a [routerLink]="['app', appid] fragment="xyz">Link</a>
https://angular.io/api/router/RouterLink

Escaping Json content

I am using AJAX function to update a row. When users click on update button, I call an AJAX function which open a div which contains all the form fields. I have rendered a template and passed that as ajax response. However my form contain a textarea inside which html tags does get escaped e.g link would display like
http://example.com/
I have used JSON.stringify, jQuery.parseJSON before populating div and twig's raw function on form filed but no success.
My form field looks like :
{{ form_widget(form.comments,{ 'value': obj.comments|raw}, {'attr':{'style':'width:'}}) }}
I believe, it has nothing to do with JSON as the template is triggered before encoding the content but I wanted to describe the whole scenario.
Controller
$content = $this->renderView("ex.html.twig", array('form'=>$form->createView()));
return new Response(json_encode($content), 200, array("Content-Type" => "application/json"));
A simple textarea cannot display "HTML" content, so it is always going to show what you call "escaped" content, as it can only display plain text. You need to find an alternative to a textarea, like a wysiwyg editor like TinyMCE or a div with the contentEditable attribute.
use JavaScript escape function after using JSON.stringify
function stringifyP(a) {
return escape(JSON.stringify(a));
}

Image not visible while exporting using Stringbuilder

Hi I am trying to get an image in an export to word.
I designed in html using string builder but i am not getting image.
My code is below. var image contains say 'Penguin.jpg'
StringBuilder head = new StringBuilder();
head.Append(#"<img src='"+Server.MapPath("")+"/img/"+image+"' alt='sdsdsd' height='42' width='42' />");
hdnOrg.Value = head.ToString();
How can i correct problem?
You are trying to assign the html to hidden field that is not the correct way, use div instead. You can assign html to InnerHtml of div. Do not forget to make div runat="server" so that you can access it in code behind. You can use also use Label or Panel etc as well instead of div.
Html
<div id="divForImg" runat="server" ></div>
Code behind
divForImg.InnerHtml = head.ToString();
If you want to reach the root path for path then you can use / forward slash and you do not need physical path rather virtual path so do not use Server.MapPath
head.Append(#"<img src='/img/" + image+ "' alt='sdsdsd' height='42' width='42' />");
As an additional note, using StringBulider here does not make much sense here as you have only one Append call and doing string concatenation on to make the path.
You are creating the the image url in the wrong way.
Server.MapPath("") is not supposed to be executed like that, with no params.
This should solve your issue
strHTMLBuilder.Append(#"<img src='file://C:\Location\img.PNG'>");

HTML link with Ajax

I have 6 different links,and each link is going to call a different Ajax function.
I'm using the <a href> tag because I want it to appear as a link....Can I use this tag to call the Ajax function? or it only works with URL links?
THANKS!
This is how I call mine. I give my elements a class name such as 'clickable' then use Jquery's click function as so.
$('.clickable').click(function() {
//do ajax
});
Then in the function, I get the id of the element as so. var id = this.id, this will get the unique id of the element.
After that I use the $.post method of Jquery, the shorthand version of ajax and complete whatever call you need to make when the user clicks that link using the id.
Of course, in my case I never use the anchor tag, I just make is a button or apply the . click to the element I wish to add the ajax call to, but you could just surround the "link" in a span or a div to simulate the same effect.
Hope this helps in some way or another.
Text
or even as they wrote, with jquery
Text
<script type="text/javascript">
$(document).load(function(){
$('#blabla').click(function(){
alert("Clicked");
});
});
</script>
Yes you can incorpore the link in the following way:
- on your link you can write ...
Here you can see further information about this topic:
What is the difference between the different methods of putting JavaScript code in an ?
You can extract the value of the href attribute and use it for your AJAX call...
(it is actually the proposed way to handle it..)
yes you can, if any client side script functions (javascript or jquery) applied than it will execute first.

Appending HTML to control and then adding an onclick event to one of the html objects?

I have a sub that writes out a bunch of HTML inside of a literal control. Part of this HTML is an image that I would like to add an onclick event to. The onclick just needs to alert a string that I have available in the same sub. ONCE THE HTML GENERATING IS COMPLETE the string to return will also be complete. So it is at this point I would need to add the onlick event to the image. But how can I do so as it won't recognize the control at this point? Thanks guys.
/**** EDIT ****/
ok so, I changed things around and I just inserted the string for the image button last so that the string to return is complete. however when the html is inserted the string kind of screws it up because of punctuation. the string could contain any number of special characters :',;" etc.
here is the line of html in the vb.net codebehind
text = "<td style='background-color:#C8DBEC;width:31px;'><img style='cursor:pointer;' id='imgPrint' src='../images/Buttons/printerbtn.png' onclick='printTranscript(" + finalText + ");' /></td>"
so my question is.. how do I need to format the finalText so that it will pass through to the javascript call?
I think your code should look like this:
text = #"<td style='background-color:#C8DBEC;width:31px;'><img style='cursor:pointer;' id='imgPrint' src='../images/Buttons/printerbtn.png' onclick='printTranscript(""" + finalText + #""");' /></td>"
I put doublequotes before and after finalText variable (inside the brackets), otherwise its value would be parsed in javascript like a varible name. I also had to place # sign at the beginning of the both strings to be able to use doublequotes
(you can read more about it here: http://msdn.microsoft.com/en-us/library/362314fe%28v=vs.71%29.aspx)
Are you using JQuery? it makes it pretty simple
$('#target').html(""');
$('#imgPrint').click(function() { printTranscript(" + finalText + "); });
I Just love JQuery
I did not test but it'll be something like that
Just bind a click event to your image. Set your alert to the finalText and voila.
$("#imgPrint").click(alert(finalText));
OR
$("#imgPrint").click(printTranscript(finalText));
finalText can be stored as an alt or title on the image and then you can grab that with jQuery as well, or you can set it in a field with display none.
With the above code you don't need an onClick on the image.