Problem with quotes in "onclick" function - onclick

I'm trying to concatenate PHP variables into an "onclick" function.
Here is the line I'm having trouble with (look for the "onclick" part):
$imagecontent = '<div class="imagensfw" id="image'.$id.'" style="width:'.round($wd).'px;height:'.round($ht).'px;" onclick="viewimage(image'.$id.','.round($wd).','.$url.');"><p>Image</div>';
I'm particularly having trouble with concatenating the $url variable. I'd want to put it between quotes, but if I do so, the "onclick" function becomes all messed up (when the code is displayed in the browser).
I think that putting the URL address ($url variable as a parameter in the onclick) between quotes will fix the error its shooting:
Error : missing ) after argument list
Here's my short Javascript function if you're interested:
function viewimage(id,width,url){
var image = document.getElementById(id);
image.innerHTML = '<img src="'+url+'" width="'+width+'" alt="Image" />';
}
Here's what I tried but didn't work (i.e. messed up the code):
onclick="viewimage(image'.$id.','.round($wd).', **"** '.$url.' **"** );"
(Noticed the double quotes added between the $url variable).
Thank you for your time.

Have you tried using variable parsing? From the link's example:
$beer = 'Heineken';
echo "He drank some ${beer}s";
This should simplify the construction of your string.

Silly me, I just noticed an error on my part. I thought we could use double quotes in an "onclick" function. Turns out not, we have to use single quotes ( ' ). It fixed my problem. Thanks!

Related

[wordpress]A shortcode that returns a shortcodes combo

I often use a combination of shortcodes to produce a line of three images. I'd like to simplify the process by creating an other shortcode that would nest the combination. Here's my code :
// [imgs img1='' img2='' img3='' height='150']
$output = '[row][col span="1/3"]
[ux_banner bg="'.$url1.'" height="'.$height.'"][/ux_banner]
[/col][col span="1/3"]
[ux_banner bg="'.$url2.'" height="'.$height.'"][/ux_banner]
[/col][col span="1/3"]
[ux_banner bg="'.$url3.'" height="'.$height.'"][/ux_banner]
[/col][/row]';
return do_shortcode($output) ;
So... well... it doesn't work. I'm a little bit confused about the nested possibilities of do_short_code. Any idea to fix my shortcode ?
Thank you !

Html ahref tag in stringbuilder

I am using html
strBody.Append("<span style=\"font-family:Arial;font-size:10pt\"> Hi " + Name + ",<br/><br/> Welcome! <br/><br/>");
strBody.Append("<tr><td style=\"font-weight:bold\">");
strBody.Append("documents for reference are shared in the Account Induction Portal ");
strBody.Append("</td><td>");
strBody.Append("Visit W3Schools<br/><br/>");
strBody.Append("</td><td>");
strBody.Append("</td></tr>");
strBody.Append("<tbody/></table><br/>");
Here href got error i cant include that in string bulider append without error.Pls help on this
you have two sets of parenthesis you must small quote for the url!
strBody.Append("<a href='http://www.w3schools.com'>Visit W3Schools</a><br/><br/>");
or escape like
strBody.Append("Visit W3Schools<br/><br/>"
You don't escape the quotes (") in the following line:
// Replace this
strBody.Append("Visit W3Schools<br/><br/>");
// with either this:
strBody.Append("Visit W3Schools<br/><br/>");
// or use single quotes inside the string:
strBody.Append("<a href='http://www.w3schools.com'>Visit W3Schools</a><br/><br/>");

How to use ? : if statements with Razor and inline code blocks

I'm updating my old .aspx views with the new Razore view engine. I have a bunch of places where I have code like this:
<span class="vote-up<%= puzzle.UserVote == VoteType.Up ? "-selected" : "" %>">Vote Up</span>
Ideally I'd like to do this:
<span class="vote-up#{puzzle.UserVote == VoteType.Up ? "-selected" : ""}">Vote Up</span>
However there's two problems here:
vote-up#{puzzle.UserVote .... is not treating the # symbol as a start of a code block
#puzzle.UserVote == VoteType.Up looks at the first part #puzzle.UserVote as if it's supposed to render the value of the variable.
Anyone know how to address these issues?
This should work:
<span class="vote-up#(puzzle.UserVote == VoteType.Up ? "-selected" : "")">Vote Up</span>
#( condition ? "true" : "false" )
The key is to encapsulate the expression in parentheses after the # delimiter. You can make any compound expression work this way.
In most cases the solution of CD.. will work perfectly fine. However I had a bit more twisted situation:
#(String.IsNullOrEmpty(Model.MaidenName) ? " " : Model.MaidenName)
This would print me " " in my page, respectively generate the source &nbsp;. Now there is a function Html.Raw(" ") which is supposed to let you write source code, except in this constellation it throws a compiler error:
Compiler Error Message: CS0173: Type of conditional expression cannot
be determined because there is no implicit conversion between
'System.Web.IHtmlString' and 'string'
So I ended up writing a statement like the following, which is less nice but works even in my case:
#if (String.IsNullOrEmpty(Model.MaidenName)) { #Html.Raw(" ") } else { #Model.MaidenName }
Note: interesting thing is, once you are inside the curly brace, you have to restart a Razor block.

Vim, css clean key map convert to function

I got this map for formating css into a one liner.
map <silent> <leader>cssclean :%s#\v/\*([^*]\|[\r\n]\|(\*+([^*/]\|[\r\n])))*\*+/##g<Bar>:call CssPretty()<Bar> :%le<Bar>:%s/{\_.\{-}}/\=substitute(submatch(0), '\n', '', 'g')/<Bar>:nohl<cr>Gdd
This map requires CssPretty.
Now I want to call this like :call CssClean() . I tried putting this one by reading this vim tip, but it didn't work.
What was the code of that function?
function CssClean()
%s#\v/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/##g
call CssPretty()
%le
%s/{\_.\{-}}/\=substitute(submatch(0), '\n', '', 'g')/
nohl
normal! Gdd
endfunction
should work fine.

Regular expression to convert substring to link

i need a Regular Expression to convert a a string to a link.i wrote something but it doesnt work in asp.net.i couldnt solve and i am new in Regular Expression.This function converts (bkz: string) to (bkz: show.aspx?td=string)
Dim pattern As String = "<bkz[a-z0-9$-$&-&.-.ö-öı-ış-şç-çğ-ğü-ü\s]+)>"
Dim regex As New Regex(pattern, RegexOptions.IgnoreCase)
str = regex.Replace(str, "<font color=""#CC0000"">$1</font>")
Generic remarks on your code: beside the lack of opening parentheses, you do redundant things: $-$ isn't incorrect but can be simplified into $ only. Same for accented chars.
Everybody will tell you that font tag is deprecated even in plain HTML: favor span with style attribute.
And from your question and the example in the reply, I think the expression could be something like:
\(bkz: ([a-z0-9$&.öışçğü\s]+)\)
the replace string would look like:
(bkz: <span style=""color: #C00"">$1</span>)
BUT the first $1 must be actually URL encoded.
Your regexp is in trouble because of a ')' without '('
Would:
<bkz:\s+((?:.(?!>))+?.)>
work better ?
The first group would capture what you are after.
Thanks Vonc,Now it doesnt raise error but also When i assign str to a Label.Text,i cant see the link too.Forexample after i bind str to my label,it should be viewed in view-source ;
<span id="Label1">(bkz: here)</span>
But now,it is in viewsource source;
<span id="Label1">(bkz: here)</span>

Resources